diff --git a/Zurnal/RemaDateBase/DateDao/PresnceDao.cs b/Zurnal/RemaDateBase/DateDao/PresnceDao.cs index 075c6da..ca8d199 100644 --- a/Zurnal/RemaDateBase/DateDao/PresnceDao.cs +++ b/Zurnal/RemaDateBase/DateDao/PresnceDao.cs @@ -2,7 +2,8 @@ { public class PresnceDao { - public Guid UserGuid { get; set; } + + public Guid UserGuid { get; set; } public bool IsAttendensy { get; set; } = true; public int LessonNumber { get; set; } public DateOnly Date { get; set; } diff --git a/Zurnal/RemaDateBase/Interfase/IGroupRepositoryes.cs b/Zurnal/RemaDateBase/Interfase/IGroupRepositoryes.cs index a838bfa..4395a88 100644 --- a/Zurnal/RemaDateBase/Interfase/IGroupRepositoryes.cs +++ b/Zurnal/RemaDateBase/Interfase/IGroupRepositoryes.cs @@ -1,17 +1,84 @@ using Zurnal.domain.Models; +using Zurnal.RemaDateBase.DateDao; using Group = System.Text.RegularExpressions.Group; namespace Zurnal.RemaDateBase { public interface IGroupRepository { - void AddGroup(Group group); - Group GetGroupById(int id); - IEnumerable GetAllGroups(); - void UpdateGroup(Group group); - void DeleteGroup(int id); - object GetAllGroup(); - bool RemoveGroupById(int groupID); - bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup); + 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; + } } } \ No newline at end of file diff --git a/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs b/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs index 49240ed..1f792fd 100644 --- a/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs +++ b/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs @@ -1,9 +1,10 @@ -using Zurnal.domain.Models; +using Zurnal.RemaDateBase.DateDao; + public interface IPresenceRepository { - void AddPresence(Presence presence); - Presence GetPresenceById(int id); - IEnumerable GetAllPresences(); - void UpdatePresence(Presence presence); + void AddPresence(PresnceDao presence); + PresnceDao GetPresenceById(int id); + IEnumerable GetAllPresences(); + void UpdatePresence(PresnceDao presence); void DeletePresence(int id); } \ No newline at end of file diff --git a/Zurnal/RemaDateBase/PresenceRepository.cs b/Zurnal/RemaDateBase/PresenceRepository.cs new file mode 100644 index 0000000..5844c9f --- /dev/null +++ b/Zurnal/RemaDateBase/PresenceRepository.cs @@ -0,0 +1,80 @@ +using Zurnal.RemaDateBase.DateDao; +public class PresenceRepository : IPresenceRepository +{ + private List presences = new List(); + + public void AddPresence(PresnceDao presence) + { + presences.Add(new PresnceDao + { + UserGuid = presence.UserGuid, + IsAttendensy = presence.IsAttendensy, + LessonNumber = presence.LessonNumber, + Date = presence.Date, + userDao = new UserDao + { + FIO = presence.userDao.FIO, + UserGuid = presence.userDao.UserGuid, + GroupID = presence.userDao.GroupID, + Group = new GroupDao { Id = presence.userDao.Group.Id, GroupName = presence.userDao.Group.GroupName } + } + }); + } + + public PresnceDao GetPresenceById(int id) + { + var presence = presences.FirstOrDefault(p => p.LessonNumber == id); + return presence != null ? new PresnceDao + { + UserGuid = presence.UserGuid, + IsAttendensy = presence.IsAttendensy, + LessonNumber = presence.LessonNumber, + Date = presence.Date, + userDao = new UserDao + { + FIO = presence.userDao.FIO, + GroupID = presence.userDao.GroupID, + Group = presence.userDao.Group + } + } : null; + } + + public IEnumerable GetAllPresences() + { + return presences.Select(p => new PresnceDao + { + UserGuid = p.UserGuid, + IsAttendensy = p.IsAttendensy, + LessonNumber = p.LessonNumber, + Date = p.Date, + userDao = new UserDao + { + FIO = p.userDao.FIO, + GroupID = p.userDao.GroupID, + Group = p.userDao.Group + } + }).ToList(); + } + + public void UpdatePresence(PresnceDao presence) + { + var existingPresence = presences.FirstOrDefault(p => p.LessonNumber == presence.LessonNumber); + if (existingPresence != null) + { + existingPresence.IsAttendensy = presence.IsAttendensy; + existingPresence.Date = presence.Date; + existingPresence.userDao.FIO = presence.userDao.FIO; + existingPresence.userDao.GroupID = presence.userDao.GroupID; + existingPresence.userDao.Group.GroupName = presence.userDao.Group.GroupName; + } + } + + public void DeletePresence(int id) + { + var presence = presences.FirstOrDefault(p => p.LessonNumber == id); + if (presence != null) + { + presences.Remove(presence); + } + } +} \ No newline at end of file diff --git a/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfo.cs b/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfo.cs index 301b687..5acf700 100644 --- a/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfo.cs +++ b/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Zurnal")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e86bec8a7f833b7d641968f35cc2ebce20da3dc8")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4f7ef7ffb28283c7077607579022f64cf7ddd780")] [assembly: System.Reflection.AssemblyProductAttribute("Zurnal")] [assembly: System.Reflection.AssemblyTitleAttribute("Zurnal")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfoInputs.cache b/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfoInputs.cache index 1a05c09..de0e327 100644 --- a/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfoInputs.cache +++ b/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfoInputs.cache @@ -1 +1 @@ -91af4bd6b85cc028ddbbf62d14f2f440aae593b748896e98c6bba89005927b76 +0c70dc958a2438c97ce99e147330083f09b6a5a64e1928d9238f0aae829439d3