From 5d31067f6b2a2a2e61a3816ecad24889acf01558 Mon Sep 17 00:00:00 2001 From: Class_Student Date: Fri, 18 Oct 2024 12:30:44 +0300 Subject: [PATCH] hello --- 123/Data/LocalData/Entity/Presence.cs | 2 +- 123/Data/LocalData/LocalStaticData.cs | 1 + .../RemoteData/RemoteDatabase/DAO/Group.cs | 15 +++++ .../RemoteData/RemoteDatabase/DAO/Presence.cs | 18 ++++++ .../RemoteData/RemoteDatabase/DAO/User.cs | 18 ++++++ .../RemoteDatabase/RemoteDatabaseContext.cs | 36 ++++++++++++ 123/Data/ReportsHistory/GroupRepositoty.cs | 29 --------- 123/Data/Repository/GroupRepositoty.cs | 55 ++++++++++++++++++ 123/Data/Repository/IGroupRepository.cs | 19 ++++++ 123/Data/Repository/IPresenceRepository.cs | 19 ++++++ 123/Data/Repository/IUserRepository.cs | 20 +++++++ 123/Data/Repository/PresenceRepository.cs | 49 ++++++++++++++++ .../UserRepositoty.cs | 8 ++- 123/Demo.csproj | 8 ++- 123/Domain/UseCase/GroupUseCase.cs | 13 +++-- 123/Domain/UseCase/PresenceUseCase.cs | 12 ++++ 123/Domain/UseCase/UseCaseGeneratePresence.cs | 13 +++++ 123/Domain/UseCase/UserUseCase.cs | 14 +++-- 123/Program.cs | 9 +++ 123/UI/GroupConsole.cs | 10 ++++ 123/UI/MainMenu.cs | 3 +- 123/UI/PresenceConsole.cs | 12 ++++ Загрузки - Ярлык.lnk | Bin 0 -> 778 bytes 23 files changed, 339 insertions(+), 44 deletions(-) create mode 100644 123/Data/RemoteData/RemoteDatabase/DAO/Group.cs create mode 100644 123/Data/RemoteData/RemoteDatabase/DAO/Presence.cs create mode 100644 123/Data/RemoteData/RemoteDatabase/DAO/User.cs create mode 100644 123/Data/RemoteData/RemoteDatabase/RemoteDatabaseContext.cs delete mode 100644 123/Data/ReportsHistory/GroupRepositoty.cs create mode 100644 123/Data/Repository/GroupRepositoty.cs create mode 100644 123/Data/Repository/IGroupRepository.cs create mode 100644 123/Data/Repository/IPresenceRepository.cs create mode 100644 123/Data/Repository/IUserRepository.cs create mode 100644 123/Data/Repository/PresenceRepository.cs rename 123/Data/{ReportsHistory => Repository}/UserRepositoty.cs (89%) create mode 100644 123/Domain/UseCase/PresenceUseCase.cs create mode 100644 123/Domain/UseCase/UseCaseGeneratePresence.cs create mode 100644 123/UI/PresenceConsole.cs create mode 100644 Загрузки - Ярлык.lnk diff --git a/123/Data/LocalData/Entity/Presence.cs b/123/Data/LocalData/Entity/Presence.cs index dde230d..fcaeeb0 100644 --- a/123/Data/LocalData/Entity/Presence.cs +++ b/123/Data/LocalData/Entity/Presence.cs @@ -8,7 +8,7 @@ namespace _123.Data.LocalData.Entity { public class PresenceLocalEntity { - public required Guid UserGuid { get; set; } + public required Guid UserGuid { get; set; } public bool IsAttedance { get; set; } = true; public required DateOnly Date { get; set; } diff --git a/123/Data/LocalData/LocalStaticData.cs b/123/Data/LocalData/LocalStaticData.cs index 2973c24..3ab7aad 100644 --- a/123/Data/LocalData/LocalStaticData.cs +++ b/123/Data/LocalData/LocalStaticData.cs @@ -1,4 +1,5 @@ using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; using System; using System.Collections.Generic; using System.Linq; diff --git a/123/Data/RemoteData/RemoteDatabase/DAO/Group.cs b/123/Data/RemoteData/RemoteDatabase/DAO/Group.cs new file mode 100644 index 0000000..ac7fe3e --- /dev/null +++ b/123/Data/RemoteData/RemoteDatabase/DAO/Group.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.RemoteData.RemoteDatabase.DAO +{ + public class GroupDao + { + public int ID { get; set; } + public required string Name { get; set; } + public IEnumerable Users { get; set; } + } +} diff --git a/123/Data/RemoteData/RemoteDatabase/DAO/Presence.cs b/123/Data/RemoteData/RemoteDatabase/DAO/Presence.cs new file mode 100644 index 0000000..bf6c3db --- /dev/null +++ b/123/Data/RemoteData/RemoteDatabase/DAO/Presence.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.RemoteData.RemoteDatabase.DAO +{ + public class PresenceDao + { + public required Guid UserGuid { get; set; } + public bool IsAttedance { get; set; } = true; + public required DateOnly Date { get; set; } + + public required int LessonNumber { get; set; } + public UserDao UserDao { get; set; } + } +} diff --git a/123/Data/RemoteData/RemoteDatabase/DAO/User.cs b/123/Data/RemoteData/RemoteDatabase/DAO/User.cs new file mode 100644 index 0000000..37cce29 --- /dev/null +++ b/123/Data/RemoteData/RemoteDatabase/DAO/User.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.RemoteData.RemoteDatabase.DAO +{ + public class UserDao + { + public required string UserFIO { get; set; } + public Guid UserGuid { get; set; } + + public required int GroupID { get; set; } + + public GroupDao Group { get; set; } + } +} diff --git a/123/Data/RemoteData/RemoteDatabase/RemoteDatabaseContext.cs b/123/Data/RemoteData/RemoteDatabase/RemoteDatabaseContext.cs new file mode 100644 index 0000000..b5f9b26 --- /dev/null +++ b/123/Data/RemoteData/RemoteDatabase/RemoteDatabaseContext.cs @@ -0,0 +1,36 @@ +using _123.Data.RemoteData.RemoteDatabase.DAO; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.RemoteData.RemoteDatabase +{ + internal class RemoteDatabaseContext: DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseNpgsql(); + } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasKey(group => group.ID); + modelBuilder.Entity().Property(group => group.ID).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(user => user.UserGuid); + modelBuilder.Entity().Property(user => user.UserGuid).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(presence => new + { + presence.UserGuid, + presence.Date, + presence.IsAttedance, + presence.LessonNumber + }); + } + public DbSet Groups { get; set; } + public DbSet Users { get; set; } + public DbSet PresencesDaos { get; set; } + } + } + diff --git a/123/Data/ReportsHistory/GroupRepositoty.cs b/123/Data/ReportsHistory/GroupRepositoty.cs deleted file mode 100644 index 079bdba..0000000 --- a/123/Data/ReportsHistory/GroupRepositoty.cs +++ /dev/null @@ -1,29 +0,0 @@ -using _123.Data.LocalData.Entity; -using _123.Data.LocalData; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace _123.Data.ReportsHistory -{ - - public class GroupRepositoryImpl - { - public List GetAllGroups() => LocalStaticData.groups; - - public GroupLocalEntity? UpdateGroup(String name) - { - GroupLocalEntity? groupLocal = GetAllGroups() - .Where(x => x.Name == name).FirstOrDefault(); - if (groupLocal == null) return null; - groupLocal.Name = name; - return groupLocal; - } - //public GroupLocalEntity AddGroup(String name, String id) - //{ - // List groups => new List - //} - } - } diff --git a/123/Data/Repository/GroupRepositoty.cs b/123/Data/Repository/GroupRepositoty.cs new file mode 100644 index 0000000..8a2b1e1 --- /dev/null +++ b/123/Data/Repository/GroupRepositoty.cs @@ -0,0 +1,55 @@ +using _123.Data.LocalData.Entity; +using _123.Data.LocalData; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using _123.Data.RemoteData.RemoteDatabase.DAO; + +namespace _123.Data.Repository +{ + + public class GroupRepositoryImpl: IGroupRepository + { + public List GetAllGroups() => LocalStaticData.groups; + public bool AddGroup(String name,String Id) + { + GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault(); + groupLocal.Name = name; + groupLocal.ID = int.Parse(Id); + return true; + } + + public List GetAllGroup() + { + return GetAllGroup(); + } + + public GroupLocalEntity GetGroupById(int groupID) + { + GroupLocalEntity? groupLocal = GetAllGroups() + .Where(x => x.ID == groupID).FirstOrDefault(); + if (groupLocal == null) return null; + return groupLocal; + } + + public bool RemoveGroupById(int groupID) + { + GroupLocalEntity? userLocal = GetAllGroups() + .Where(x => x.ID == groupID).FirstOrDefault(); + if (userLocal == null) return false; + return GetAllGroups().Remove(userLocal); + } + + public bool UpdateGroupById(int groupID, String name) + { + GroupLocalEntity? groupLocal = GetAllGroups() + .Where(x => x.ID == groupID).FirstOrDefault(); + if (groupLocal == null) return false; + groupLocal.Name = name; + return true; + } + } + } + diff --git a/123/Data/Repository/IGroupRepository.cs b/123/Data/Repository/IGroupRepository.cs new file mode 100644 index 0000000..810dc41 --- /dev/null +++ b/123/Data/Repository/IGroupRepository.cs @@ -0,0 +1,19 @@ +using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.Repository +{ + internal interface IGroupRepository + { + List GetAllGroup(); + bool RemoveGroupById(int groupID); + bool UpdateGroupById(int groupID, String name); + GroupLocalEntity GetGroupById(int groupID); + bool AddGroup(String name, String id); + } +} diff --git a/123/Data/Repository/IPresenceRepository.cs b/123/Data/Repository/IPresenceRepository.cs new file mode 100644 index 0000000..5a22e99 --- /dev/null +++ b/123/Data/Repository/IPresenceRepository.cs @@ -0,0 +1,19 @@ +using _123.Data.LocalData.Entity; +using _123.Domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.Repository +{ + interface IPresenceRepository + { + List GetPresenceByGroup(int groupId); + List GetPresenceByGroupAndDate(int groupId, DateOnly date); + void UnCheckAttendence (PresenceLocalEntity presence); + void AddPresence (PresenceLocalEntity presence); + + } +} diff --git a/123/Data/Repository/IUserRepository.cs b/123/Data/Repository/IUserRepository.cs new file mode 100644 index 0000000..09ff06c --- /dev/null +++ b/123/Data/Repository/IUserRepository.cs @@ -0,0 +1,20 @@ +using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.Repository +{ + internal interface IUserRepository + { + public List GetAllUsers(); + bool RemoveUserByGuid(Guid userGuid); + UserLocalEntity FindUserByGuid(Guid userGuid); + UserLocalEntity? GetUserByGuid(Guid userGuid); + UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity); + UserLocalEntity? UpdateUserByGuid(Guid userGuid); + } +} diff --git a/123/Data/Repository/PresenceRepository.cs b/123/Data/Repository/PresenceRepository.cs new file mode 100644 index 0000000..dd96fcf --- /dev/null +++ b/123/Data/Repository/PresenceRepository.cs @@ -0,0 +1,49 @@ +using _123.Data.LocalData; +using _123.Data.LocalData.Entity; +using _123.Domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace _123.Data.Repository +{ + public class PresenceRepositoryImpl : IPresenceRepository + + { + public PresenceRepositoryImpl() + { + GetAllPresences = LocalStaticData.presences; + } + public List GetAllPresences + { get; set; } + + public void AddPresence(PresenceLocalEntity presence) + { + PresenceLocalEntity? presenceLocal = GetAllPresences.FirstOrDefault(); + presenceLocal.UserGuid = presence.UserGuid; + presenceLocal.Date = presence.Date; + presenceLocal.IsAttedance = presence.IsAttedance; + presenceLocal.LessonNumber = presence.LessonNumber; + + } + + public List GetPresenceByGroup(int groupId) + { + + } + + public List GetPresenceByGroupAndDate(int groupId, DateOnly date) + { + throw new NotImplementedException(); + } + + public void UnCheckAttendence(Presence presence) + { + throw new NotImplementedException(); + } + } + +} diff --git a/123/Data/ReportsHistory/UserRepositoty.cs b/123/Data/Repository/UserRepositoty.cs similarity index 89% rename from 123/Data/ReportsHistory/UserRepositoty.cs rename to 123/Data/Repository/UserRepositoty.cs index 5d8f5e2..e3e133c 100644 --- a/123/Data/ReportsHistory/UserRepositoty.cs +++ b/123/Data/Repository/UserRepositoty.cs @@ -1,5 +1,7 @@ using _123.Data.LocalData; using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; +using _123.Data.Repository; using System; using System.Collections.Generic; using System.Linq; @@ -9,7 +11,7 @@ using System.Xml.Linq; namespace _123.Data.ReportsHistory { - public class UserRepositoryImpl + public class UserRepositoryImpl: IUserRepository { public UserRepositoryImpl() { @@ -64,5 +66,9 @@ namespace _123.Data.ReportsHistory } + List IUserRepository.GetAllUsers() + { + throw new NotImplementedException(); + } } } diff --git a/123/Demo.csproj b/123/Demo.csproj index ebb8a92..47c142b 100644 --- a/123/Demo.csproj +++ b/123/Demo.csproj @@ -9,7 +9,13 @@ - + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + diff --git a/123/Domain/UseCase/GroupUseCase.cs b/123/Domain/UseCase/GroupUseCase.cs index 4d08baf..e36ef4a 100644 --- a/123/Domain/UseCase/GroupUseCase.cs +++ b/123/Domain/UseCase/GroupUseCase.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using _123.Domain.Models; using _123.Data.LocalData.Entity; +using _123.Data.Repository; namespace _123.Domain.UseCase { @@ -19,13 +20,13 @@ namespace _123.Domain.UseCase public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() .Select(it => new Group { ID = it.ID, Name = it.Name }).ToList(); - public Group UpdateGroupName(String name, String name1) + public bool UpdateGroupName(String id, String name1) { - GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(name); - if (result == null) throw new Exception(""); - Group? group = GetAllGroups().FirstOrDefault(it => it.Name == result!.Name); - if (group == null) throw new Exception(""); - return new Group { ID = group.ID, Name = name1 }; + return _repositoryGroupImpl.UpdateGroupById(int.Parse(id), name1); + } + public bool AddGroup(String name, string id) + { + return _repositoryGroupImpl.AddGroup(name, id); } } diff --git a/123/Domain/UseCase/PresenceUseCase.cs b/123/Domain/UseCase/PresenceUseCase.cs new file mode 100644 index 0000000..1cad8a4 --- /dev/null +++ b/123/Domain/UseCase/PresenceUseCase.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Domain.UseCase +{ + class PresenceUseCase + { + } +} diff --git a/123/Domain/UseCase/UseCaseGeneratePresence.cs b/123/Domain/UseCase/UseCaseGeneratePresence.cs new file mode 100644 index 0000000..6927465 --- /dev/null +++ b/123/Domain/UseCase/UseCaseGeneratePresence.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Domain.UseCase +{ + internal class UseCaseGeneratePresence + { + + } +} diff --git a/123/Domain/UseCase/UserUseCase.cs b/123/Domain/UseCase/UserUseCase.cs index 95d70bf..f073de2 100644 --- a/123/Domain/UseCase/UserUseCase.cs +++ b/123/Domain/UseCase/UserUseCase.cs @@ -1,5 +1,7 @@ using _123.Data.LocalData.Entity; +using _123.Data.RemoteData.RemoteDatabase.DAO; using _123.Data.ReportsHistory; +using _123.Data.Repository; using _123.Domain.Models; using System; using System.Collections.Generic; @@ -11,8 +13,10 @@ namespace _123.Domain.UseCase { public class UserUseCase { - private UserRepositoryImpl _repositoryUserImpl; - private GroupRepositoryImpl _repositoryGroupImpl; + //private readonly UserRepositoryImpl _repositoryUserImpl; + //private readonly GroupRepositoryImpl _repositoryGroupImpl; + private readonly UserRepositoryImpl _repositoryUserImpl; + private readonly IGroupRepository _repositoryGroupImpl; public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) { @@ -20,10 +24,10 @@ namespace _123.Domain.UseCase _repositoryGroupImpl = repositoryGroupImpl; } - public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() + public List GetAllGroups() => _repositoryGroupImpl.GetAllGroup() .Select(it => new Group { ID = it.ID, Name = it.Name }).ToList(); - public List GetAllUsers() => _repositoryUserImpl.GetAllUsers - .Join(_repositoryGroupImpl.GetAllGroups(), + private List GetAllUsers() => _repositoryUserImpl.GetAllUsers + .Join(_repositoryGroupImpl.GetAllGroup(), user => user.GroupID, group => group.ID, (user, group) => diff --git a/123/Program.cs b/123/Program.cs index b9d7ee3..03eec2b 100644 --- a/123/Program.cs +++ b/123/Program.cs @@ -1,6 +1,15 @@ using _123.Data.ReportsHistory; +using _123.Data.Repository; using _123.Domain.UseCase; using _123.UI; +using Microsoft.Extensions.DependencyInjection; +using System.Text.RegularExpressions; + +IServiceCollection services = new ServiceCollection(); +services + .AddSingleton() + .AddSingleton(); +var serviceProvider = services.BuildServiceProvider (); GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl(); diff --git a/123/UI/GroupConsole.cs b/123/UI/GroupConsole.cs index e19ce86..6d145d2 100644 --- a/123/UI/GroupConsole.cs +++ b/123/UI/GroupConsole.cs @@ -33,5 +33,15 @@ namespace _123.UI } Console.WriteLine(groupOutput); } + public void AddGroup (String name, String id) + { + StringBuilder groupOutput = new StringBuilder(); + var group = _groupUseCase.AddGroup(name,id); + { + groupOutput.AppendLine($"{group.Name}\t{group.ID}"); + } + Console.WriteLine(groupOutput); + } + } } \ No newline at end of file diff --git a/123/UI/MainMenu.cs b/123/UI/MainMenu.cs index 40d666c..8099cb6 100644 --- a/123/UI/MainMenu.cs +++ b/123/UI/MainMenu.cs @@ -34,7 +34,8 @@ namespace _123.UI case "3": _groupConsoleUI.DisplayAllGroups(); break; case "4": _userConsoleUI.FindUserByGuid(Guid.Parse(Console.ReadLine()));break; case "5": _userConsoleUI.UpdateUserByGuid(Guid.Parse(Console.ReadLine()),Console.ReadLine(), Console.ReadLine()); break; - case "6": _groupConsoleUI.UpdateGroupName(Console.ReadLine(),Console.ReadLine()); break; + case "6": _groupConsoleUI.UpdateGroupName(Console.ReadLine(),Console.ReadLine()); break; + case "7": _groupConsoleUI.AddGroup(Console.ReadLine(), Console.ReadLine());break; default: DisplayMenu(); break; diff --git a/123/UI/PresenceConsole.cs b/123/UI/PresenceConsole.cs new file mode 100644 index 0000000..3de68aa --- /dev/null +++ b/123/UI/PresenceConsole.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.UI +{ + internal class PresenceConsole + { + } +} diff --git a/Загрузки - Ярлык.lnk b/Загрузки - Ярлык.lnk new file mode 100644 index 0000000000000000000000000000000000000000..dc2ead35e19005a3cf5d3fb03aa8261b1b494649 GIT binary patch literal 778 zcmeZaU|?VrVFHp23V)(6f-a|G3Wtd0z~722p|mt$@vAjx+c12x<&?I zzFE~do$tp@{C5fGRg3G{Op}4274fF4>ZRBs1jrf9}t60fyE$*UkJn?w=K&`*07y=NpR~mh6DaLB`$;l#pOT> zKsG1>F}n9+@B~K;g9}4GLpd;La)5LqFqnXm3I&!x8f4){v0Rt6y#*f2Jsk9w*jDt& Z0>v{xYCM40P3l??h|R!Y07^P2007dirN#gN literal 0 HcmV?d00001