diff --git a/Data/Repository/GroupRepositoryImpl.cs b/Data/Repository/GroupRepositoryImpl.cs index 37573eb..ce3812b 100644 --- a/Data/Repository/GroupRepositoryImpl.cs +++ b/Data/Repository/GroupRepositoryImpl.cs @@ -13,13 +13,12 @@ namespace Posechaemost.Data.Repository public class GroupRepositoryImpl { public List GetAllGroups() => LocalStaticData.groups; - public GroupLocalEntity? UpdateGroup(GroupLocalEntity groupUpdateLocalEnity) + public GroupLocalEntity? UpdateGroup(String name) { GroupLocalEntity? groupLocal = GetAllGroups() - .Where(x => x.Id == groupUpdateLocalEnity.Id).FirstOrDefault(); + .Where(x => x.Name == name).FirstOrDefault(); if (groupLocal == null) return null; - groupLocal.Id = groupUpdateLocalEnity.Id; - groupLocal.Name = groupUpdateLocalEnity.Name; + groupLocal.Name = name; return groupLocal; } diff --git a/Data/Repository/UserRepositoryImpl.cs b/Data/Repository/UserRepositoryImpl.cs index d41a3c7..bfd4af8 100644 --- a/Data/Repository/UserRepositoryImpl.cs +++ b/Data/Repository/UserRepositoryImpl.cs @@ -44,5 +44,12 @@ namespace Posechaemost.Data.Repository return userLocal; } + + public UserLocalEntity? UpdateUserByGuid(Guid userGuid) { + UserLocalEntity? userLocal = GetAllUsers + .Where(x => x.Guid == userGuid).FirstOrDefault(); + if (userLocal == null) return null; + return userLocal; + } } } \ No newline at end of file diff --git a/Domain/Models/User.cs b/Domain/Models/User.cs index 79282f5..cb48ac2 100644 --- a/Domain/Models/User.cs +++ b/Domain/Models/User.cs @@ -9,6 +9,6 @@ namespace Posechaemost.Domain.Models public class User{ public required string FIO {get; set; } public Guid Guid {get; set;} - public required Group Group {get; set;} + public required Group GroupId {get; set;} } } \ No newline at end of file diff --git a/Domain/UseCase/GroupUseCase.cs b/Domain/UseCase/GroupUseCase.cs index 9b8ba42..0989a5c 100644 --- a/Domain/UseCase/GroupUseCase.cs +++ b/Domain/UseCase/GroupUseCase.cs @@ -21,13 +21,12 @@ namespace Posechaemost.Domain.UseCase public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); - public Group UpdateGroupName(Group grou) { - GroupLocalEntity groupLocalEntity = new GroupLocalEntity {Id = grou.Id, Name = grou.Name}; - GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity); + public Group UpdateGroupName(String name, String name1) { + 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}; } } } \ No newline at end of file diff --git a/Domain/UseCase/UserUseCase.cs b/Domain/UseCase/UserUseCase.cs index 95cbfda..e3cd964 100644 --- a/Domain/UseCase/UserUseCase.cs +++ b/Domain/UseCase/UserUseCase.cs @@ -29,7 +29,7 @@ namespace Posechaemost.Domain.UseCase (user, group) => new User { FIO = user.FIO, Guid = user.Guid, - Group = new Group {Id = group.Id, Name = group.Name } } + GroupId = new Group {Id = group.Id, Name = group.Name } } ).ToList(); @@ -37,16 +37,24 @@ namespace Posechaemost.Domain.UseCase return _repositoryUserImpl.RemoveUserByGuid(userGuid); } public User UpdateUser(User user) { - UserLocalEntity userLocalEnity = new UserLocalEntity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid }; + UserLocalEntity userLocalEnity = new UserLocalEntity { FIO = user.FIO, GroupID = user.GroupId.Id, Guid = user.Guid }; UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEnity); if (result == null) throw new Exception(""); Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.GroupID); if (group == null) throw new Exception(""); - return new User { FIO = user.FIO, Guid = user.Guid, Group = group}; + return new User { FIO = user.FIO, Guid = user.Guid, GroupId = group}; } public UserLocalEntity GetUserByGuid(Guid userGuid) { return _repositoryUserImpl.GetUserByGuid(userGuid); } + + public User UpdateUserByGuid(Guid userGuid, String fio, String groupId) { + UserLocalEntity? result = _repositoryUserImpl.UpdateUserByGuid(userGuid); + if (result == null) throw new Exception(""); + Group? group = GetAllGroups().FirstOrDefault(it => it.Id == int.Parse(groupId)); + if (group == null) throw new Exception(""); + return new User { FIO = fio, GroupId = group, Guid = userGuid }; + } } } \ No newline at end of file diff --git a/UI/GroupConsole.cs b/UI/GroupConsole.cs index ef7bba6..6cee2d5 100644 --- a/UI/GroupConsole.cs +++ b/UI/GroupConsole.cs @@ -1,3 +1,4 @@ +using Posechaemost.Domain.Models; using Posechaemost.Domain.UseCase; using System; using System.Collections.Generic; @@ -23,5 +24,12 @@ namespace Posechaemost.UI } Console.WriteLine(groupOutput); } + + public void UpdateGroupName(String name, String name1) { + StringBuilder userOutput = new StringBuilder(); + var group = _groupUseCase.UpdateGroupName(name, name1); + userOutput.AppendLine($"{group.Id}\t{group.Name}"); + Console.WriteLine(userOutput); + } } } diff --git a/UI/MainMenu.cs b/UI/MainMenu.cs index a55aeac..abb0c2a 100644 --- a/UI/MainMenu.cs +++ b/UI/MainMenu.cs @@ -32,6 +32,8 @@ namespace Posechaemost.UI case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break; case "3": _groupConsoleUI.DisplayAllGroups(); break; case "4": _userConsoleUI.GetUserByGuid(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/UI/UserConsole.cs b/UI/UserConsole.cs index 6fe60dc..aedc9b0 100644 --- a/UI/UserConsole.cs +++ b/UI/UserConsole.cs @@ -1,3 +1,4 @@ +using Posechaemost.Data.LocalData.Entity; using Posechaemost.Domain.UseCase; using System; using System.Collections.Generic; @@ -25,7 +26,7 @@ namespace Posechaemost.UI StringBuilder userOutput = new StringBuilder(); foreach (var user in _userUseCase.GetAllUsers()) { - userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.Group.Name}"); + userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupId.Name}"); } Console.WriteLine(userOutput); } @@ -36,8 +37,14 @@ namespace Posechaemost.UI userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupID}"); Console.WriteLine(userOutput); } + + public void UpdateUserByGuid(Guid userGuid, String name, String groupId) { + StringBuilder userOutput = new StringBuilder(); + var user = _userUseCase.UpdateUserByGuid(userGuid, name, groupId); + userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupId.Name}"); + Console.WriteLine(userOutput); } - + } } diff --git a/bin/Debug/net8.0/Posechaemost.dll b/bin/Debug/net8.0/Posechaemost.dll index 520c7ad..69ba9e8 100644 Binary files a/bin/Debug/net8.0/Posechaemost.dll and b/bin/Debug/net8.0/Posechaemost.dll differ diff --git a/bin/Debug/net8.0/Posechaemost.pdb b/bin/Debug/net8.0/Posechaemost.pdb index a5c68d6..cda548f 100644 Binary files a/bin/Debug/net8.0/Posechaemost.pdb and b/bin/Debug/net8.0/Posechaemost.pdb differ diff --git a/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs b/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs index 4260318..fcfa405 100644 --- a/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs +++ b/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs @@ -13,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2043a0253af9ebde32c83e4366bb2ddff439b3bd")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2adf9afa836f2195e7d6875eb60914f8f6544ee9")] [assembly: System.Reflection.AssemblyProductAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyTitleAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Generated by the MSBuild WriteCodeFragment class. +// Создано классом WriteCodeFragment MSBuild. diff --git a/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache b/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache index e10c3ff..1085738 100644 --- a/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache +++ b/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache @@ -1 +1 @@ -23fad0f77cb5c1fcd312e88f594bb29098487a4c55237df8836db88abd48689f +96bf08b88313635c8c7dfa5999c9c749997058383865f8a634f20c197c546273 diff --git a/obj/Debug/net8.0/Posechaemost.dll b/obj/Debug/net8.0/Posechaemost.dll index 520c7ad..69ba9e8 100644 Binary files a/obj/Debug/net8.0/Posechaemost.dll and b/obj/Debug/net8.0/Posechaemost.dll differ diff --git a/obj/Debug/net8.0/Posechaemost.pdb b/obj/Debug/net8.0/Posechaemost.pdb index a5c68d6..cda548f 100644 Binary files a/obj/Debug/net8.0/Posechaemost.pdb and b/obj/Debug/net8.0/Posechaemost.pdb differ diff --git a/obj/Debug/net8.0/ref/Posechaemost.dll b/obj/Debug/net8.0/ref/Posechaemost.dll index 517a034..e941e92 100644 Binary files a/obj/Debug/net8.0/ref/Posechaemost.dll and b/obj/Debug/net8.0/ref/Posechaemost.dll differ diff --git a/obj/Debug/net8.0/refint/Posechaemost.dll b/obj/Debug/net8.0/refint/Posechaemost.dll index 517a034..e941e92 100644 Binary files a/obj/Debug/net8.0/refint/Posechaemost.dll and b/obj/Debug/net8.0/refint/Posechaemost.dll differ