diff --git a/Data/Entity/User.cs b/Data/Entity/User.cs index 1d14a68..bb58849 100644 --- a/Data/Entity/User.cs +++ b/Data/Entity/User.cs @@ -9,5 +9,5 @@ namespace Demo.Domain.Models{ if (other == null) return false; return this.Guid.Equals(other.Guid); } -} + } } \ No newline at end of file diff --git a/Data/Repository/IUserRepository.cs b/Data/Repository/IUserRepository.cs index a57dd9d..16629e7 100644 --- a/Data/Repository/IUserRepository.cs +++ b/Data/Repository/IUserRepository.cs @@ -6,6 +6,7 @@ namespace Demo.Data.Repository { List GetAllUser(); UserLocalEntity? GetUserByGuid(Guid guid); + List GetUsersByGroupID(int groupID); bool RemoveUserByGuid(Guid guid); UserLocalEntity? UpdateUser(UserLocalEntity updatedUser); } diff --git a/Data/Repository/UserRepositorylmpl.cs b/Data/Repository/UserRepositorylmpl.cs index ea4090c..c5965d8 100644 --- a/Data/Repository/UserRepositorylmpl.cs +++ b/Data/Repository/UserRepositorylmpl.cs @@ -25,6 +25,19 @@ namespace Demo.Data.Repository return new UserLocalEntity{FIO = userDAO.FIO, GroupID = userDAO.GroupID, Guid = guid}; } + public List GetUsersByGroupID(int groupID) + { + return _remoteDatabaseContext.Users + .Where(x => x.GroupID == groupID) // Фильтруем пользователей по GroupID + .Select(x => new UserLocalEntity + { + FIO = x.FIO, + Guid = x.Guid, + GroupID = x.GroupID // Устанавливаем фактический GroupID + }) + .ToList(); + } + public bool RemoveUserByGuid(Guid guid){ var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == guid); _remoteDatabaseContext.Users.Remove(userDAO); diff --git a/Domain/UseCase/IPresenceUseCase.cs b/Domain/UseCase/IPresenceUseCase.cs index f8c1c66..8a1d588 100644 --- a/Domain/UseCase/IPresenceUseCase.cs +++ b/Domain/UseCase/IPresenceUseCase.cs @@ -6,6 +6,9 @@ namespace Demo.Domain.UseCase { List GetPresenceByGroup(int groupID); List GetPresenceByGroupByTime(int groupID, DateOnly date); + List GetPresenceByUser(Guid userGuid); + List GetFalsePresenceByUser(Guid userGuid); + List GetFalsePresenceByGroup(int groupID); bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid); bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date); bool GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date); diff --git a/Domain/UseCase/IUserUseCase.cs b/Domain/UseCase/IUserUseCase.cs index 98f2b15..96a00b1 100644 --- a/Domain/UseCase/IUserUseCase.cs +++ b/Domain/UseCase/IUserUseCase.cs @@ -8,5 +8,6 @@ namespace Demo.Domain.UseCase bool RemoveUserByGuid(Guid userGuid); User UpdateUser(User user); User GetUserByGuid(Guid userGuid); + List GetUsersByGroupID(int groupID); } } \ No newline at end of file diff --git a/Domain/UseCase/PresenceUseCase.cs b/Domain/UseCase/PresenceUseCase.cs index 847cd05..7170fd6 100644 --- a/Domain/UseCase/PresenceUseCase.cs +++ b/Domain/UseCase/PresenceUseCase.cs @@ -39,6 +39,73 @@ namespace Demo.Domain.UseCase return presenceByGroup; } + + public List GetFalsePresenceByGroup(int groupID){ + var usersByGroup = _repositoryUserImpl.GetAllUser() + .Where(user => user.GroupID == groupID).ToList(); + + var presenceByGroup = _repositoryPresenceImpl.GetAllPresences() + .Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid) && x.IsAttedance == false) + .Select(presence => new Presence{ + User = new User{ + Guid = presence.UserGuid, + Group = new Group{ + ID = groupID, + Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name + }, + FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO, + }, + LessonNumber = presence.LessonNumber, + Date = presence.Date, + IsAttedance = presence.IsAttedance + }).ToList(); + + return presenceByGroup; + } + + public List GetPresenceByUser(Guid userGuid){ + var user = _repositoryUserImpl.GetUserByGuid(userGuid); + + var presenceByUser = _repositoryPresenceImpl.GetAllPresences() + .Where(user => userGuid == user.UserGuid) + .Select(presence => new Presence{ + User = new User{ + Guid = user.Guid, + Group = new Group{ + ID = user.GroupID, + Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == user.GroupID).Name + }, + FIO = user.FIO + }, + LessonNumber = presence.LessonNumber, + Date = presence.Date, + IsAttedance = presence.IsAttedance + }).ToList(); + + return presenceByUser; + } + + public List GetFalsePresenceByUser(Guid userGuid){ + var user = _repositoryUserImpl.GetUserByGuid(userGuid); + + var presenceByUser = _repositoryPresenceImpl.GetAllPresences() + .Where(user => userGuid == user.UserGuid && user.IsAttedance == false) + .Select(presence => new Presence{ + User = new User{ + Guid = user.Guid, + Group = new Group{ + ID = user.GroupID, + Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == user.GroupID).Name + }, + FIO = user.FIO + }, + LessonNumber = presence.LessonNumber, + Date = presence.Date, + IsAttedance = presence.IsAttedance + }).ToList(); + + return presenceByUser; + } public List GetPresenceByGroupByTime(int groupID, DateOnly date){ var usersByGroup = _repositoryUserImpl.GetAllUser() diff --git a/Domain/UseCase/UserUseCase.cs b/Domain/UseCase/UserUseCase.cs index 49a5547..2c675f9 100644 --- a/Domain/UseCase/UserUseCase.cs +++ b/Domain/UseCase/UserUseCase.cs @@ -44,6 +44,23 @@ namespace Demo.Domain.UseCase }; } + public List GetUsersByGroupID(int groupID){ + List localUsers = _repositoryUserImpl.GetUsersByGroupID(groupID); + if (localUsers == null) throw new Exception("bello"); + Group? group = GetAllGroups().FirstOrDefault(it => groupID == it.ID); + if (group == null) throw new Exception("bello"); + List users = localUsers.Select(userLocal => new User{ + FIO = userLocal.FIO, + Guid = userLocal.Guid, + Group = new Group{ + Name = group.Name, + ID = group.ID + } + }).ToList(); + + return users; + } + public bool RemoveUserByGuid(Guid userGuid) { return _repositoryUserImpl.RemoveUserByGuid(userGuid); } diff --git a/UI/MainMenu.cs b/UI/MainMenu.cs index f12b713..3271606 100644 --- a/UI/MainMenu.cs +++ b/UI/MainMenu.cs @@ -12,7 +12,7 @@ namespace Demo.UI public MainMenuUI(IUserUseCase userUseCase, IGroupUseCase groupUseCase, IPresenceUseCase presenceUseCase) { _userConsoleUI = new UserConsoleUI(userUseCase); - _groupConsoleUI = new GroupConsoleUI(groupUseCase); + _groupConsoleUI = new GroupConsoleUI(groupUseCase, userUseCase, presenceUseCase); _presenceConsoleUI = new PresenceConsoleUI(presenceUseCase); DisplayMenu(); @@ -23,6 +23,7 @@ namespace Demo.UI { switch (Console.ReadLine()) { + case "0": _groupConsoleUI.DisplayAllBoutGroup(Convert.ToInt32(Console.ReadLine())); break; case "1": _groupConsoleUI.DisplayAllGroups(); break; case "2": _groupConsoleUI.CreateNewGroup(Console.ReadLine()); break; case "3": _groupConsoleUI.UpdateGroupName(Group.Parse(Console.ReadLine())); break; diff --git a/UI/UserConsole.cs b/UI/UserConsole.cs index 6087a45..0fac04f 100644 --- a/UI/UserConsole.cs +++ b/UI/UserConsole.cs @@ -1,3 +1,4 @@ +using System.ComponentModel.DataAnnotations; using System.Text; using Demo.Domain.Models; using Demo.Domain.UseCase; @@ -53,8 +54,12 @@ namespace Demo.UI public class GroupConsoleUI { IGroupUseCase _groupUseCase; - public GroupConsoleUI(IGroupUseCase groupUseCase){ + IUserUseCase _userUseCase; + IPresenceUseCase _presenceUseCase; + public GroupConsoleUI(IGroupUseCase groupUseCase, IUserUseCase userUseCase, IPresenceUseCase presenceUseCase){ _groupUseCase = groupUseCase; + _userUseCase = userUseCase; + _presenceUseCase = presenceUseCase; } public void DisplayAllGroups(){ @@ -99,6 +104,32 @@ namespace Demo.UI string output = _groupUseCase.RemoveGroupByID(ID) ? "Группа удалена" : "Группа не удалена"; Console.WriteLine(output); } + + public void DisplayAllBoutGroup(int groupID){ + var users = _userUseCase.GetUsersByGroupID(groupID); + Console.WriteLine($"Группа: {groupID}\tКоличество учеников: {users.Count}"); + + var presencesByGroup = _presenceUseCase.GetPresenceByGroup(groupID); + var presenceFalseByGroup = _presenceUseCase.GetFalsePresenceByGroup(groupID); + var precentePresenceGroup = 100 - Math.Round((double)presenceFalseByGroup.Count / presencesByGroup.Count * 100); + Console.WriteLine($"Количество занятий: {presencesByGroup.Count}\tОбщий процент посещаемости: {precentePresenceGroup}"); + + foreach(var user in _userUseCase.GetUsersByGroupID(groupID)){ + var countPresences = _presenceUseCase.GetPresenceByUser(user.Guid); + var countFalsePresences = _presenceUseCase.GetFalsePresenceByUser(user.Guid); + var precentePresenceUser = 100 - Math.Round((double)countFalsePresences.Count / countPresences.Count * 100); + if (precentePresenceUser < 40) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"FIO: {user.FIO}\tКоличество посещённых занятий: {countPresences.Count - countFalsePresences.Count}\tКоличество пропущенных занятий: {countFalsePresences.Count}\tПроцент посещаемости: {precentePresenceUser}"); + Console.ResetColor(); + } + else + { + Console.WriteLine($"FIO: {user.FIO}\tКоличество посещённых занятий: {countPresences.Count - countFalsePresences.Count}\tКоличество пропущенных занятий: {countFalsePresences.Count}\tПроцент посещаемости: {precentePresenceUser}"); + } + } + } } public class PresenceConsoleUI{ diff --git a/bin/Debug/net8.0/Demo.dll b/bin/Debug/net8.0/Demo.dll index 6ec0ffe..f8b0467 100644 Binary files a/bin/Debug/net8.0/Demo.dll and b/bin/Debug/net8.0/Demo.dll differ diff --git a/bin/Debug/net8.0/Demo.pdb b/bin/Debug/net8.0/Demo.pdb index 517064d..363a54f 100644 Binary files a/bin/Debug/net8.0/Demo.pdb and b/bin/Debug/net8.0/Demo.pdb differ diff --git a/obj/Debug/net8.0/Demo.AssemblyInfo.cs b/obj/Debug/net8.0/Demo.AssemblyInfo.cs index 62e830d..6314378 100644 --- a/obj/Debug/net8.0/Demo.AssemblyInfo.cs +++ b/obj/Debug/net8.0/Demo.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Demo")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ea99225579b2fe5759998c1d40840070bd9463e0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+86b4759087deeb63dff8a43a0ff879e320f29457")] [assembly: System.Reflection.AssemblyProductAttribute("Demo")] [assembly: System.Reflection.AssemblyTitleAttribute("Demo")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache b/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache index 7cd2fd8..942bd83 100644 --- a/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache +++ b/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache @@ -1 +1 @@ -80d5c4821e3ff98a41b6c458f427344bd492e44a8a96d916098f8470ef998b85 +06f206715bfe1384818fd42aad58f6d1ef0f893f41ccdcce066ace7c594fd406 diff --git a/obj/Debug/net8.0/Demo.dll b/obj/Debug/net8.0/Demo.dll index 6ec0ffe..f8b0467 100644 Binary files a/obj/Debug/net8.0/Demo.dll and b/obj/Debug/net8.0/Demo.dll differ diff --git a/obj/Debug/net8.0/Demo.pdb b/obj/Debug/net8.0/Demo.pdb index 517064d..363a54f 100644 Binary files a/obj/Debug/net8.0/Demo.pdb and b/obj/Debug/net8.0/Demo.pdb differ diff --git a/obj/Debug/net8.0/ref/Demo.dll b/obj/Debug/net8.0/ref/Demo.dll index b948faf..d7a95f2 100644 Binary files a/obj/Debug/net8.0/ref/Demo.dll and b/obj/Debug/net8.0/ref/Demo.dll differ diff --git a/obj/Debug/net8.0/refint/Demo.dll b/obj/Debug/net8.0/refint/Demo.dll index b948faf..d7a95f2 100644 Binary files a/obj/Debug/net8.0/refint/Demo.dll and b/obj/Debug/net8.0/refint/Demo.dll differ