diff --git a/Demo/Data/LocalData/LocalStaticData.cs b/Demo/Data/LocalData/LocalStaticData.cs index aebb784..92c7f91 100644 --- a/Demo/Data/LocalData/LocalStaticData.cs +++ b/Demo/Data/LocalData/LocalStaticData.cs @@ -10,7 +10,7 @@ namespace Demo.Data.LocalData { public static class LocalStaticData { - public static IEnumerable groups => new List + public static List groups => new List { new GroupLocalEntity{ Id = 1, Name = "ИП1-21" }, diff --git a/Demo/Data/Repository/GroupRepositoryImpl.cs b/Demo/Data/Repository/GroupRepositoryImpl.cs new file mode 100644 index 0000000..e5b9a29 --- /dev/null +++ b/Demo/Data/Repository/GroupRepositoryImpl.cs @@ -0,0 +1,15 @@ +using Demo.Data.LocalData; +using Demo.domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.Data.Repository +{ + public class GroupRepositoryImpl + { + public List GetAllGroups() => LocalStaticData.groups; + } +} diff --git a/Demo/Data/Repository/UserRepositoryImpl.cs b/Demo/Data/Repository/UserRepositoryImpl.cs index 9d802fd..93fab95 100644 --- a/Demo/Data/Repository/UserRepositoryImpl.cs +++ b/Demo/Data/Repository/UserRepositoryImpl.cs @@ -10,7 +10,7 @@ namespace Demo.Data.Repository { public class UserRepositoryImpl { - public IEnumerable GetAllUsers() => LocalStaticData.users; + public List GetAllUsers() => LocalStaticData.users; public bool RemoveUserByGuid(Guid userGuid) { @@ -31,7 +31,7 @@ namespace Demo.Data.Repository return userLocal; } - public UserLocalEnity? UpdateUserByGuid(UserLocalEnity userUpdateLocalEnity) { + public UserLocalEnity? UpdateUser(UserLocalEnity userUpdateLocalEnity) { UserLocalEnity? userLocal = LocalStaticData .users .Where(x => x.Guid == userUpdateLocalEnity.Guid).FirstOrDefault(); diff --git a/Demo/Domain/UseCase/UserUseCase.cs b/Demo/Domain/UseCase/UserUseCase.cs index b98a077..f0a507d 100644 --- a/Demo/Domain/UseCase/UserUseCase.cs +++ b/Demo/Domain/UseCase/UserUseCase.cs @@ -1,4 +1,5 @@ using Demo.Data.Repository; +using Demo.domain.Models; using System; using System.Collections.Generic; using System.Linq; @@ -9,12 +10,34 @@ namespace Demo.Domain.UseCase { public class UserUseCase { - private UserRepositoryImpl _repositoryImpl; + private UserRepositoryImpl _repositoryUserImpl; + private GroupRepositoryImpl _repositoryGroupImpl; - public UserUseCase(UserRepositoryImpl repositoryImpl) + public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) { - _repositoryImpl = repositoryImpl; + _repositoryUserImpl = repositoryImpl; + _repositoryGroupImpl = repositoryGroupImpl; } + public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() + .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); + public List GetAllUsers => _repositoryUserImpl.GetAllUsers() + .Join(_repositoryGroupImpl.GetAllGroups(), + user => user.GroupID, + group => group.Id, + (user, group) => + new User { FIO = user.FIO, + Guid = user.Guid, + Group = new Group {Id = group.Id, Name = group.Name } } + ).ToList(); + + public User UpdateUser(User user) { + UserLocalEnity userLocalEnity = new UserLocalEnity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid }; + UserLocalEnity? 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}; + } } } diff --git a/Demo/Program.cs b/Demo/Program.cs index 5f28270..da2898d 100644 --- a/Demo/Program.cs +++ b/Demo/Program.cs @@ -1 +1,20 @@ - \ No newline at end of file + + +using Demo.Data.Repository; +using Demo.domain.Models; +using Demo.Domain.UseCase; + +GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); +UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl(); +UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl); + +List users = userUseCase.GetAllUsers; + +foreach (var user in users) { + Console.WriteLine($"{user.FIO} группа {user.Group.Name}"); +} + +userUseCase. + + +Console.ReadKey(); \ No newline at end of file