diff --git a/123/Data/LocalData/LocalStaticData.cs b/123/Data/LocalData/LocalStaticData.cs index f65a867..2973c24 100644 --- a/123/Data/LocalData/LocalStaticData.cs +++ b/123/Data/LocalData/LocalStaticData.cs @@ -17,12 +17,12 @@ namespace _123.Data.LocalData }; public static List users => new List { - new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio", GroupID = 1 }, - new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio1", GroupID = 2 }, - new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio2", GroupID = 3 }, - new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio3", GroupID = 1 }, - new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio4", GroupID = 2 }, - new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio5", GroupID = 3 }, + new UserLocalEntity{UserGuid=Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), UserFIO = "RandomFio", GroupID = 1 }, + new UserLocalEntity{UserGuid=Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), UserFIO = "RandomFio1", GroupID = 2 }, + new UserLocalEntity{UserGuid=Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), UserFIO = "RandomFio2", GroupID = 3 }, + new UserLocalEntity{UserGuid=Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), UserFIO = "RandomFio3", GroupID = 1 }, + new UserLocalEntity{UserGuid=Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), UserFIO = "RandomFio4", GroupID = 2 }, + new UserLocalEntity{UserGuid=Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), UserFIO = "RandomFio5", GroupID = 3 }, }; public static List presences => new List { diff --git a/123/Data/ReportsHistory/GroupRepositoty.cs b/123/Data/ReportsHistory/GroupRepositoty.cs index a84260b..079bdba 100644 --- a/123/Data/ReportsHistory/GroupRepositoty.cs +++ b/123/Data/ReportsHistory/GroupRepositoty.cs @@ -13,14 +13,17 @@ namespace _123.Data.ReportsHistory { public List GetAllGroups() => LocalStaticData.groups; - public GroupLocalEntity? UpdateGroup(GroupLocalEntity groupUpdateLocalEntity) + public GroupLocalEntity? UpdateGroup(String name) { GroupLocalEntity? groupLocal = GetAllGroups() - .Where(x => x.ID == groupUpdateLocalEntity.ID).FirstOrDefault(); + .Where(x => x.Name == name).FirstOrDefault(); if (groupLocal == null) return null; - groupLocal.ID = groupUpdateLocalEntity.ID; - groupLocal.Name = groupUpdateLocalEntity.Name; + groupLocal.Name = name; return groupLocal; } + //public GroupLocalEntity AddGroup(String name, String id) + //{ + // List groups => new List + //} } } diff --git a/123/Data/ReportsHistory/UserRepositoty.cs b/123/Data/ReportsHistory/UserRepositoty.cs index 3bdc09b..5d8f5e2 100644 --- a/123/Data/ReportsHistory/UserRepositoty.cs +++ b/123/Data/ReportsHistory/UserRepositoty.cs @@ -27,6 +27,14 @@ namespace _123.Data.ReportsHistory return GetAllUsers.Remove(userLocal); } + public UserLocalEntity FindUserByGuid(Guid userGuid) + { + UserLocalEntity? userLocal = GetAllUsers + .Where(x => x.UserGuid == userGuid).FirstOrDefault(); + if (userLocal == null) throw new Exception("Пользователь не найден"); + return userLocal; + } + public UserLocalEntity? GetUserByGuid(Guid userGuid) { @@ -47,5 +55,14 @@ namespace _123.Data.ReportsHistory return userLocal; } + public UserLocalEntity? UpdateUserByGuid(Guid userGuid) + { + UserLocalEntity? userLocal = GetAllUsers + .Where(x => x.UserGuid == userGuid).FirstOrDefault(); + if (userLocal == null) return null; + return userLocal; + + } + } } diff --git a/123/Domain/UseCase/GroupUseCase.cs b/123/Domain/UseCase/GroupUseCase.cs index b877f3b..4d08baf 100644 --- a/123/Domain/UseCase/GroupUseCase.cs +++ b/123/Domain/UseCase/GroupUseCase.cs @@ -19,14 +19,13 @@ namespace _123.Domain.UseCase public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() .Select(it => new Group { ID = it.ID, Name = it.Name }).ToList(); - public Group UpdateGroupName(Group grou) + public Group UpdateGroupName(String name, String name1) { - GroupLocalEntity groupLocalEntity = new GroupLocalEntity { ID = grou.ID, Name = grou.Name }; - GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity); + GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(name); if (result == null) throw new Exception(""); - Group? group = GetAllGroups().FirstOrDefault(it => it.ID == result!.ID); + Group? group = GetAllGroups().FirstOrDefault(it => it.Name == result!.Name); if (group == null) throw new Exception(""); - return new Group { ID = group.ID, Name = group.Name }; + return new Group { ID = group.ID, Name = name1 }; } } diff --git a/123/Domain/UseCase/UserUseCase.cs b/123/Domain/UseCase/UserUseCase.cs index 212048b..95d70bf 100644 --- a/123/Domain/UseCase/UserUseCase.cs +++ b/123/Domain/UseCase/UserUseCase.cs @@ -48,6 +48,17 @@ namespace _123.Domain.UseCase if (group == null) throw new Exception(""); return new User { UserFIO = user.UserFIO, UserGuid = user.UserGuid, UserGroup = group }; } - + public UserLocalEntity FindUserByGuid(Guid userGuid) + { + return _repositoryUserImpl.FindUserByGuid(userGuid); + } + public UserLocalEntity UpdateUserByGuid(Guid userGuid, String name, String gro) + { + UserLocalEntity? result = _repositoryUserImpl.UpdateUserByGuid(userGuid); + if (result == null) throw new Exception(""); + Group? group = GetAllGroups().FirstOrDefault(it => it.ID == int.Parse(gro)); + if (group == null) throw new Exception(""); + return new UserLocalEntity { UserFIO = name, GroupID = int.Parse(gro), UserGuid = userGuid}; + } } } diff --git a/123/UI/GroupConsole.cs b/123/UI/GroupConsole.cs index 2bb3fdb..e19ce86 100644 --- a/123/UI/GroupConsole.cs +++ b/123/UI/GroupConsole.cs @@ -1,3 +1,5 @@ +using _123.Data.LocalData.Entity; +using _123.Domain.Models; using _123.Domain.UseCase; using System; using System.Collections.Generic; @@ -22,5 +24,14 @@ namespace _123.UI } Console.WriteLine(groupOutput); } + public void UpdateGroupName(String name, String name1) + { + StringBuilder groupOutput = new StringBuilder(); + var group = _groupUseCase.UpdateGroupName(name,name1); + { + 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 c06b921..40d666c 100644 --- a/123/UI/MainMenu.cs +++ b/123/UI/MainMenu.cs @@ -32,7 +32,9 @@ namespace _123.UI case "1": _userConsoleUI.DisplayAllUsers(); break; case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break; 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; default: DisplayMenu(); break; diff --git a/123/UI/UserConsole.cs b/123/UI/UserConsole.cs index 1007378..c85aa36 100644 --- a/123/UI/UserConsole.cs +++ b/123/UI/UserConsole.cs @@ -1,4 +1,6 @@ -using _123.Domain.UseCase; +using _123.Data.LocalData.Entity; +using _123.Domain.Models; +using _123.Domain.UseCase; using System; using System.Collections.Generic; using System.Linq; @@ -31,6 +33,23 @@ namespace _123.UI } Console.WriteLine(userOutput); } - + public void FindUserByGuid (Guid guidUser) + { + StringBuilder userOutput = new StringBuilder(); + var user = _userUseCase.FindUserByGuid(guidUser); + { + userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.GroupID}"); + } + Console.WriteLine(userOutput); + } + public void UpdateUserByGuid(Guid userGuid,String name,String group) + { + StringBuilder userOutput = new StringBuilder(); + var user = _userUseCase.UpdateUserByGuid(userGuid,name,group); + { + userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.GroupID}"); + } + Console.WriteLine(userOutput); + } } }