79 lines
2.0 KiB
C#
79 lines
2.0 KiB
C#
using Zurnal.RemaDateBase.DateDao;
|
|
|
|
internal interface IGroupRepository
|
|
{
|
|
List<GroupDao> AllGroup { get; }
|
|
|
|
public IEnumerable<GroupDao> AllGroups()
|
|
{
|
|
return AllGroup.Select(g => new GroupDao { GroupName = g.GroupName, Id = g.Id });
|
|
}
|
|
|
|
public bool RemoveGroupById(int groupId)
|
|
{
|
|
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
|
|
if (group != null)
|
|
{
|
|
AllGroup.Remove(group);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public GroupDao FindGroupById(int groupId)
|
|
{
|
|
return AllGroup.FirstOrDefault(g => g.Id == groupId);
|
|
}
|
|
|
|
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)
|
|
{
|
|
group.GroupName = updatedGroup.GroupName;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void DeleteGroup(int id)
|
|
{
|
|
var group = AllGroup.FirstOrDefault(g => g.Id == id);
|
|
if (group != null)
|
|
{
|
|
AllGroup.Remove(group);
|
|
}
|
|
}
|
|
|
|
public IEnumerable<GroupDao> GetAllGroups()
|
|
{
|
|
return AllGroup;
|
|
}
|
|
|
|
public void UpdateGroupName(int groupId, string name)
|
|
{
|
|
if (name == null) throw new ArgumentNullException(nameof(name));
|
|
|
|
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
|
|
if (group != null)
|
|
{
|
|
group.GroupName = name;
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
} |