diff --git a/Data/Repository/IPresenceRepository.cs b/Data/Repository/IPresenceRepository.cs new file mode 100644 index 0000000..880ebde --- /dev/null +++ b/Data/Repository/IPresenceRepository.cs @@ -0,0 +1,12 @@ +using Demo.Domain.Models; + +namespace Demo.Data.Repository +{ + public interface IPresenceRepository + { + List GetAllPresences(); + List? GetPresenceByGroup(); + List GetPresenceByGroupDate(); + List GeneratePresence(List presenceLocalEntities); + } +} \ No newline at end of file diff --git a/Data/Repository/PresenceRepositoryImpl.cs b/Data/Repository/PresenceRepositoryImpl.cs new file mode 100644 index 0000000..ad7d57d --- /dev/null +++ b/Data/Repository/PresenceRepositoryImpl.cs @@ -0,0 +1,27 @@ +using Demo.Data.LocalData; +using Demo.Domain.Models; + +namespace Demo.Data.Repository +{ + public class PresenceRepositoryImpl : IPresenceRepository + { + public List GetAllPresence = new List{}; + + public List GetAllPresences(){ + return GetAllPresence; + } + + public List? GetPresenceByGroup(){ + return GetAllPresence; + } + + public List GetPresenceByGroupDate(){ + return GetAllPresence; + } + + public List GeneratePresence(List presenceLocalEntities){ + GetAllPresence.AddRange(presenceLocalEntities); + return presenceLocalEntities; + } + } +} \ No newline at end of file diff --git a/Domain/UseCase/IPresenceUseCase.cs b/Domain/UseCase/IPresenceUseCase.cs new file mode 100644 index 0000000..261491f --- /dev/null +++ b/Domain/UseCase/IPresenceUseCase.cs @@ -0,0 +1,11 @@ +using Demo.Domain.Models; + +namespace Demo.Domain.UseCase +{ + public interface IPresenceUseCase + { + List GetPresenceByGroup(int groupID); + List GetPresenceByGroupByTime(int groupID, DateOnly date); + bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date); + } +} \ No newline at end of file diff --git a/Domain/UseCase/PresenceUseCase.cs b/Domain/UseCase/PresenceUseCase.cs new file mode 100644 index 0000000..4b02494 --- /dev/null +++ b/Domain/UseCase/PresenceUseCase.cs @@ -0,0 +1,98 @@ +using System.Security.Cryptography.X509Certificates; +using Demo.Data.Repository; +using Demo.Domain.Models; + +namespace Demo.Domain.UseCase +{ + public class PresenceUseCase : IPresenceUseCase + { + private readonly IUserRepository _repositoryUserImpl; + private readonly IPresenceRepository _repositoryPresenceImpl; + private readonly IGroupRepository _repositoryGroupImpl; + + public PresenceUseCase(IPresenceRepository repositoryPresenceImpl, IUserRepository repositoryUserImpl, IGroupRepository repositoryGroupImpl) + { + _repositoryPresenceImpl = repositoryPresenceImpl; + _repositoryUserImpl = repositoryUserImpl; + _repositoryGroupImpl = repositoryGroupImpl; + } + + public List GetPresenceByGroup(int groupID){ + var usersByGroup = _repositoryUserImpl.GetAllUser() + .Where(user => user.GroupID == groupID).ToList(); + + var presenceByGroup = _repositoryPresenceImpl.GetPresenceByGroup() + .Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid)) + .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 GetPresenceByGroupByTime(int groupID, DateOnly date){ + var usersByGroup = _repositoryUserImpl.GetAllUser() + .Where(user => user.GroupID == groupID).ToList(); + + var presenceByGroup = _repositoryPresenceImpl.GetPresenceByGroup() + .Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid && x.Date == date)) + .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 bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date){ + List presenceList = new List{}; + var usersByGroup = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupID); + for (int i = firstLesson; i <= lastLesson; i++){ + foreach(UserLocalEntity user in usersByGroup){ + presenceList.Add(new Presence{ + User = new User{ + Group = new Group{ + ID = groupID, + Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name + }, + FIO = usersByGroup.First(user2 => user2.Guid == user.Guid).FIO, + Guid = user.Guid + }, + IsAttedance = true, + Date = date, + LessonNumber = i}); + } + } + + var presenceLocalEntity = presenceList.Select(x => new PresenceLocalEntity{ + UserGuid = x.User.Guid, + IsAttedance = x.IsAttedance, + LessonNumber = x.LessonNumber, + Date = x.Date + }).ToList(); + + _repositoryPresenceImpl.GeneratePresence(presenceLocalEntity); + + return true; + } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 43970eb..4ffca78 100644 --- a/Program.cs +++ b/Program.cs @@ -8,8 +8,10 @@ IServiceCollection services = new ServiceCollection(); services .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton(); diff --git a/UI/MainMenu.cs b/UI/MainMenu.cs index 5cfabff..35fd8fa 100644 --- a/UI/MainMenu.cs +++ b/UI/MainMenu.cs @@ -8,10 +8,12 @@ namespace Demo.UI UserConsoleUI _userConsoleUI; GroupConsoleUI _groupConsoleUI; + PresenceConsoleUI _presenceConsoleUI; - public MainMenuUI(IUserUseCase userUseCase, IGroupUseCase groupUseCase) { + public MainMenuUI(IUserUseCase userUseCase, IGroupUseCase groupUseCase, IPresenceUseCase presenceUseCase) { _userConsoleUI = new UserConsoleUI(userUseCase); _groupConsoleUI = new GroupConsoleUI(groupUseCase); + _presenceConsoleUI = new PresenceConsoleUI(presenceUseCase); DisplayMenu(); } @@ -28,6 +30,12 @@ namespace Demo.UI case "5": _groupConsoleUI.DisplayAllGroups(); break; case "6": _groupConsoleUI.CreateNewGroup(Group.Parse(Console.ReadLine())); break; case "7": _groupConsoleUI.UpdateGroupName(Group.Parse(Console.ReadLine())); break; //todo + + case "10": Console.WriteLine("писяпопакака"); break; + + case "777": _presenceConsoleUI.DisplayPresenceByGroup(Convert.ToInt32(Console.ReadLine())); break; + case "888": _presenceConsoleUI.DisplayPresenceByGroupByTime(Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break; + case "999": _presenceConsoleUI.GeneratePresence(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break; default: DisplayMenu(); break; diff --git a/UI/UserConsole.cs b/UI/UserConsole.cs index 2dae6a6..d788dc1 100644 --- a/UI/UserConsole.cs +++ b/UI/UserConsole.cs @@ -67,7 +67,8 @@ namespace Demo.UI } public void CreateNewGroup(Group group){ - string output = _groupUseCase.CreateGroup(group) ? "Пользователь создан" : "Пользователь не создан"; + string output = _groupUseCase.CreateGroup(group) ? "Группа создана" : "Группа не создана"; + Console.WriteLine(output); } public void UpdateGroupName(Group group) @@ -85,4 +86,32 @@ namespace Demo.UI } } } + + public class PresenceConsoleUI{ + IPresenceUseCase _presenceUseCase; + public PresenceConsoleUI (IPresenceUseCase presenceUseCase){ + _presenceUseCase = presenceUseCase; + } + + public void DisplayPresenceByGroup(int groupID){ + StringBuilder stringBuilder = new StringBuilder(); + foreach(Presence presence in _presenceUseCase.GetPresenceByGroup(groupID)){ + stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}"); + } + Console.WriteLine(stringBuilder); + } + + public void DisplayPresenceByGroupByTime(int groupID, DateOnly date){ + StringBuilder stringBuilder = new StringBuilder(); + foreach(Presence presence in _presenceUseCase.GetPresenceByGroupByTime(groupID, date)){ + stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}"); + } + Console.WriteLine(stringBuilder); + } + + public void GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date){ + string output = _presenceUseCase.GeneratePresence(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно"; + Console.WriteLine(output); + } + } } \ No newline at end of file diff --git a/bin/Debug/net8.0/Demo.dll b/bin/Debug/net8.0/Demo.dll index 9120ffd..004f83b 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 6908802..131f007 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 032a045..860a7c0 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+efdaa788226f9fa951e2ae58165ff21fe7ad3343")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+62cf71e0807e9e3240bed91fc96a70ca85f326da")] [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 3d721d6..bf8e6c2 100644 --- a/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache +++ b/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache @@ -1 +1 @@ -48f599dad06dd9ec07676f26c2418560d03b7411954018e21ccf3036a6416f34 +a01cfb167fed9f2405a5e73c2f292e1435aae3d26590e7f2368a0b28d9d0813e diff --git a/obj/Debug/net8.0/Demo.csproj.CoreCompileInputs.cache b/obj/Debug/net8.0/Demo.csproj.CoreCompileInputs.cache index 1985122..6a2e448 100644 --- a/obj/Debug/net8.0/Demo.csproj.CoreCompileInputs.cache +++ b/obj/Debug/net8.0/Demo.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -73b1ce81cd1614d1fb79d966e9c834dbbfe2456209fddcd2419a154a7bcb8cef +09be6b06af3e5ac830f9b11348702d6b725bd1a0b9782c4a38dcd83e5849bf9b diff --git a/obj/Debug/net8.0/Demo.dll b/obj/Debug/net8.0/Demo.dll index 9120ffd..004f83b 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 6908802..131f007 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 891d5a3..e62f0f4 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 891d5a3..e62f0f4 100644 Binary files a/obj/Debug/net8.0/refint/Demo.dll and b/obj/Debug/net8.0/refint/Demo.dll differ