using Zurnal.domain.Models; using Zurnal.RemaDateBase.DateDao; using Group = System.Text.RegularExpressions.Group; namespace Zurnal.RemaDateBase { public interface IGroupRepository { List AllGroup { get; } public IEnumerable 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 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; } } }