Raspisanie/Zurnal/Date/Repository/IGroupRepository.cs

80 lines
2.1 KiB
C#
Raw Permalink Normal View History

2024-11-07 11:31:00 +00:00
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
2024-10-21 11:56:16 +00:00
2024-11-02 10:59:07 +00:00
internal interface IGroupRepository
2024-10-21 11:56:16 +00:00
{
2024-11-02 10:59:07 +00:00
List<GroupDao> AllGroup { get; }
public IEnumerable<GroupDao> AllGroups()
2024-11-01 07:49:39 +00:00
{
2024-11-02 10:59:07 +00:00
return AllGroup.Select(g => new GroupDao { GroupName = g.GroupName, Id = g.Id });
}
2024-11-07 11:31:00 +00:00
List<GroupLocalEntity> GetAllGroup();
2024-11-02 10:59:07 +00:00
public bool RemoveGroupById(int groupId)
{
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
if (group != null)
2024-11-02 10:40:07 +00:00
{
2024-11-02 10:59:07 +00:00
AllGroup.Remove(group);
return true;
2024-11-02 10:40:07 +00:00
}
2024-11-02 10:59:07 +00:00
return false;
}
public GroupDao FindGroupById(int groupId)
2024-11-02 10:40:07 +00:00
{
2024-11-02 10:59:07 +00:00
return AllGroup.FirstOrDefault(g => g.Id == groupId);
2024-11-02 10:40:07 +00:00
}
2024-11-02 10:59:07 +00:00
public bool UpdateGroupById(int groupId, GroupDao updatedGroup)
{
if (updatedGroup == null) throw new ArgumentNullException(nameof(updatedGroup));
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
if (group != null)
2024-11-02 10:40:07 +00:00
{
2024-11-02 10:59:07 +00:00
group.GroupName = updatedGroup.GroupName;
return true;
2024-11-02 10:40:07 +00:00
}
2024-11-02 10:59:07 +00:00
return false;
}
public void DeleteGroup(int id)
2024-11-02 10:40:07 +00:00
{
2024-11-02 10:59:07 +00:00
var group = AllGroup.FirstOrDefault(g => g.Id == id);
if (group != null)
{
AllGroup.Remove(group);
}
2024-11-02 10:40:07 +00:00
}
2024-11-02 10:59:07 +00:00
public IEnumerable<GroupDao> GetAllGroups()
{
return AllGroup;
2024-11-01 07:49:39 +00:00
}
2024-10-31 11:37:45 +00:00
2024-11-02 10:59:07 +00:00
public void UpdateGroupName(int groupId, string name)
2024-10-31 11:37:45 +00:00
{
2024-11-02 10:59:07 +00:00
if (name == null) throw new ArgumentNullException(nameof(name));
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
if (group != null)
2024-10-31 11:37:45 +00:00
{
2024-11-02 10:59:07 +00:00
group.GroupName = name;
2024-10-31 11:37:45 +00:00
}
}
2024-11-06 07:13:11 +00:00
public bool UpdateUser(Guid userGuid, UserDao updatedUser)
{
if (updatedUser == null) throw new ArgumentNullException(nameof(updatedUser));
var user = AllGroup.SelectMany(g => g.Users).FirstOrDefault(u => u.UserGuid == userGuid);
if (user != null)
{
user.FIO = updatedUser.FIO;
user.GroupID = updatedUser.GroupID;
user.Group = updatedUser.Group;
return true;
}
return false;
}
2024-10-31 11:37:45 +00:00
}