diff --git a/Demo/Data/LocalData/Entity/User.cs b/Demo/Data/LocalData/Entity/User.cs index 08479f2..5af4881 100644 --- a/Demo/Data/LocalData/Entity/User.cs +++ b/Demo/Data/LocalData/Entity/User.cs @@ -6,11 +6,19 @@ using System.Threading.Tasks; namespace Demo.domain.Models { - public class UserLocalEnity + public class UserLocalEnity : IEquatable { public required string FIO { get; set; } public Guid Guid { get; set; } public required int GroupID { get; set; } + + + + public bool Equals(UserLocalEnity? other) + { + if (other == null) return false; + return this.Guid.Equals(other.Guid); + } } } diff --git a/Demo/Data/LocalData/LocalStaticData.cs b/Demo/Data/LocalData/LocalStaticData.cs index 92c7f91..50e54f7 100644 --- a/Demo/Data/LocalData/LocalStaticData.cs +++ b/Demo/Data/LocalData/LocalStaticData.cs @@ -18,14 +18,14 @@ namespace Demo.Data.LocalData new GroupLocalEntity{ Id = 3, Name = "ИП1-23" }, }; - public static List users => new List + public static List users => new List { - new UserLocalEnity{Guid=Guid.NewGuid(), FIO = "RandomFio", GroupID = 1 }, - new UserLocalEnity{Guid=Guid.NewGuid(), FIO = "RandomFio1", GroupID = 2 }, - new UserLocalEnity{Guid=Guid.NewGuid(), FIO = "RandomFio2", GroupID = 3 }, - new UserLocalEnity{Guid=Guid.NewGuid(), FIO = "RandomFio3", GroupID = 1 }, - new UserLocalEnity{Guid=Guid.NewGuid(), FIO = "RandomFio4", GroupID = 2 }, - new UserLocalEnity{Guid=Guid.NewGuid(), FIO = "RandomFio5", GroupID = 3 }, + new UserLocalEnity{Guid=Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), FIO = "RandomFio", GroupID = 1 }, + new UserLocalEnity{Guid=Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), FIO = "RandomFio1", GroupID = 2 }, + new UserLocalEnity{Guid=Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), FIO = "RandomFio2", GroupID = 3 }, + new UserLocalEnity{Guid=Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), FIO = "RandomFio3", GroupID = 1 }, + new UserLocalEnity{Guid=Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), FIO = "RandomFio4", GroupID = 2 }, + new UserLocalEnity{Guid=Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), FIO = "RandomFio5", GroupID = 3 }, }; } } diff --git a/Demo/Data/Repository/UserRepositoryImpl.cs b/Demo/Data/Repository/UserRepositoryImpl.cs index 93fab95..bf9ae8c 100644 --- a/Demo/Data/Repository/UserRepositoryImpl.cs +++ b/Demo/Data/Repository/UserRepositoryImpl.cs @@ -10,21 +10,24 @@ namespace Demo.Data.Repository { public class UserRepositoryImpl { - public List GetAllUsers() => LocalStaticData.users; + public UserRepositoryImpl() { + + GetAllUsers = LocalStaticData.users; + } + public List GetAllUsers + { get; set; } public bool RemoveUserByGuid(Guid userGuid) { - UserLocalEnity? userLocal = LocalStaticData - .users + UserLocalEnity? userLocal = GetAllUsers .Where(x => x.Guid == userGuid).FirstOrDefault(); if (userLocal == null) return false; - return LocalStaticData.users.Remove(userLocal); + return GetAllUsers.Remove(userLocal); } public UserLocalEnity? GetUserByGuid(Guid userGuid) { - UserLocalEnity? userLocal = LocalStaticData - .users + UserLocalEnity? userLocal = GetAllUsers .Where(x => x.Guid == userGuid).FirstOrDefault(); if (userLocal == null) return null; @@ -32,8 +35,7 @@ namespace Demo.Data.Repository } public UserLocalEnity? UpdateUser(UserLocalEnity userUpdateLocalEnity) { - UserLocalEnity? userLocal = LocalStaticData - .users + UserLocalEnity? userLocal = GetAllUsers .Where(x => x.Guid == userUpdateLocalEnity.Guid).FirstOrDefault(); if (userLocal == null) return null; userLocal.FIO = userUpdateLocalEnity.FIO; diff --git a/Demo/Domain/UseCase/UserUseCase.cs b/Demo/Domain/UseCase/UserUseCase.cs index f0a507d..f1f44e1 100644 --- a/Demo/Domain/UseCase/UserUseCase.cs +++ b/Demo/Domain/UseCase/UserUseCase.cs @@ -21,7 +21,7 @@ namespace Demo.Domain.UseCase public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); - public List GetAllUsers => _repositoryUserImpl.GetAllUsers() + public List GetAllUsers() => _repositoryUserImpl.GetAllUsers .Join(_repositoryGroupImpl.GetAllGroups(), user => user.GroupID, group => group.Id, @@ -31,6 +31,9 @@ namespace Demo.Domain.UseCase Group = new Group {Id = group.Id, Name = group.Name } } ).ToList(); + public bool RemoveUserByGuid(Guid userGuid) { + return _repositoryUserImpl.RemoveUserByGuid(userGuid); + } public User UpdateUser(User user) { UserLocalEnity userLocalEnity = new UserLocalEnity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid }; UserLocalEnity? result = _repositoryUserImpl.UpdateUser(userLocalEnity); diff --git a/Demo/UI/MainMenu.cs b/Demo/UI/MainMenu.cs index f93611a..ce13884 100644 --- a/Demo/UI/MainMenu.cs +++ b/Demo/UI/MainMenu.cs @@ -14,7 +14,23 @@ namespace Demo.UI public MainMenuUI(UserUseCase userUseCase) { _userConsoleUI = new UserConsoleUI(userUseCase); - _userConsoleUI.DisplayAllUsers(); + DisplayMenu(); + + } + + private void DisplayMenu() { + while (true) + { + switch (Console.ReadLine()) + { + case "1": _userConsoleUI.DisplayAllUsers(); break; + case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break; + + default: DisplayMenu(); + break; + } + + } } } diff --git a/Demo/UI/UserConsole.cs b/Demo/UI/UserConsole.cs index 81aadda..15ec296 100644 --- a/Demo/UI/UserConsole.cs +++ b/Demo/UI/UserConsole.cs @@ -14,10 +14,16 @@ namespace Demo.UI _userUseCase = userUseCase; } + public void RemoveUserByGuid(Guid guidUser) { + + string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален"; + Console.WriteLine(output); + } + public void DisplayAllUsers() { StringBuilder userOutput = new StringBuilder(); - foreach (var user in _userUseCase.GetAllUsers) + foreach (var user in _userUseCase.GetAllUsers()) { userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.Group.Name}"); }