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 0000000..dc2ead3 Binary files /dev/null and b/Загрузки - Ярлык.lnk differ