diff --git a/Zurnal/Date/Repository/GroupRepositoryImpl.cs b/Zurnal/Date/Repository/GroupRepositoryImpl.cs index a504798..1542f87 100644 --- a/Zurnal/Date/Repository/GroupRepositoryImpl.cs +++ b/Zurnal/Date/Repository/GroupRepositoryImpl.cs @@ -40,10 +40,7 @@ namespace Zurnal.Data.Repository throw new NotImplementedException(); } - public List GetAllGroup() - { - throw new NotImplementedException(); - } + public List AllGroup => throw new NotImplementedException(); public bool RemoveGroupById(int groupID) { @@ -59,5 +56,30 @@ namespace Zurnal.Data.Repository { throw new NotImplementedException(); } + + public void AddGroupFromRegex(System.Text.RegularExpressions.Group group) + { + throw new NotImplementedException(); + } + + System.Text.RegularExpressions.Group IGroupRepository.GetGroupById(int id) + { + throw new NotImplementedException(); + } + + IEnumerable IGroupRepository.GetAllGroups() + { + throw new NotImplementedException(); + } + + public void UpdateGroup(System.Text.RegularExpressions.Group group) + { + throw new NotImplementedException(); + } + + public void DeleteGroup(int id) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/Zurnal/Date/Repository/IGroupRepository.cs b/Zurnal/Date/Repository/IGroupRepository.cs index f1a5236..879f438 100644 --- a/Zurnal/Date/Repository/IGroupRepository.cs +++ b/Zurnal/Date/Repository/IGroupRepository.cs @@ -1,4 +1,4 @@ -using Zurnal.domain.Models; +using Zurnal.RemaDateBase.DateDao; using Microsoft.Extensions.DependencyInjection; using Zurnal.Data.Repository; using Group = System.Text.RegularExpressions.Group; @@ -6,17 +6,19 @@ using Group = System.Text.RegularExpressions.Group; namespace Zurnal.Date.Repository { internal interface IGroupRepository -{ - List GetAllGroup(); - bool RemoveGroupById(int groupID); - bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup); - bool AddGroup(GroupLocalEntity newGroup); - void AddGroupFromRegex(Group group); - Group GetGroupById(int id); - IEnumerable GetAllGroups(); - void UpdateGroup(Group group); - void DeleteGroup(int id); -} + { + List AllGroup { get; } + + IEnumerable AllGroups(); + bool RemoveGroupById(int groupID); + bool UpdateGroupById(int groupID, GroupDao updatedGroup); + bool AddGroup(GroupDao newGroup); + void AddGroupFromRegex(Group group); + GroupDao GetGroupById(int id); + IEnumerable GetAllGroups(); + void UpdateGroup(GroupDao group); + void DeleteGroup(int id); + } internal class ServiceConfiguration { diff --git a/Zurnal/Date/Repository/UserRepositoryImpl.cs b/Zurnal/Date/Repository/UserRepositoryImpl.cs index 3bd51b6..86b2cef 100644 --- a/Zurnal/Date/Repository/UserRepositoryImpl.cs +++ b/Zurnal/Date/Repository/UserRepositoryImpl.cs @@ -68,10 +68,7 @@ namespace Zurnal.Data.Repository throw new NotImplementedException(); } - public List GetAllGroup() - { - throw new NotImplementedException(); - } + public List AllGroup => throw new NotImplementedException(); internal UserUseCase.UserLocalEntity? UpdateUser(UserUseCase.UserLocalEntity userLocalEntity) { diff --git a/Zurnal/Domain/Model/Group.cs b/Zurnal/Domain/Model/Group.cs index f4d262e..d977e66 100644 --- a/Zurnal/Domain/Model/Group.cs +++ b/Zurnal/Domain/Model/Group.cs @@ -1,14 +1,25 @@ -namespace Zurnal.domain.Models +using Zurnal.RemaDateBase.DateDao; + +namespace Zurnal.domain.Models { public class Group { public required int Id { get; set; } public required string Name { get; set; } - public static implicit operator Group(GroupLocalEntity v) + public static implicit operator Group?(GroupLocalEntity? v) { throw new NotImplementedException(); } + public static implicit operator Guid(Group v) + { + throw new NotImplementedException(); + } + + public static implicit operator Group?(GroupDao? v) + { + throw new NotImplementedException(); + } } } diff --git a/Zurnal/Domain/Model/User.cs b/Zurnal/Domain/Model/User.cs index 169270c..7643660 100644 --- a/Zurnal/Domain/Model/User.cs +++ b/Zurnal/Domain/Model/User.cs @@ -2,6 +2,8 @@ { public class User { + internal int Id; + public required string FIO { get; set; } public Guid Guid { get; set; } diff --git a/Zurnal/Domain/UseCase/UserUseCase.cs b/Zurnal/Domain/UseCase/UserUseCase.cs index 73c6a01..2860b17 100644 --- a/Zurnal/Domain/UseCase/UserUseCase.cs +++ b/Zurnal/Domain/UseCase/UserUseCase.cs @@ -1,7 +1,7 @@ using Zurnal.Data.Repository; using Zurnal.Date.Repository; using Zurnal.domain.Models; - +using Zurnal.RemaDateBase.DateDao; namespace Zurnal.Domain.UseCase { @@ -15,20 +15,15 @@ namespace Zurnal.Domain.UseCase _repositoryUserImpl = repositoryImpl; RepositoryGroupImpl = (IGroupRepository?)(repositoryGroupImpl ?? throw new ArgumentNullException(nameof(repositoryGroupImpl))); } - private object NewMethod() - { - return RepositoryGroupImpl.GetAllGroup() - .Select(it => new Group { Id = it.Id, Name = it.Name }); - } public List GetAllUsers() => _repositoryUserImpl.GetAllUsersList() - .Join(RepositoryGroupImpl.GetAllGroup(), + .Join(RepositoryGroupImpl.AllGroup, 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 } } + Group = new Group { Id = group.Id, Name = group.GroupName } } ).ToList(); public bool RemoveUserByGuid(Guid userGuid) @@ -36,37 +31,40 @@ namespace Zurnal.Domain.UseCase return _repositoryUserImpl.RemoveUserByGuid(userGuid); } - public User UpdateUser(User user, Guid id) + public User UpdateUser(User user, Group id) { UserLocalEntity userLocalEntity = new UserLocalEntity { FIO = user.FIO, GroupID = id, Guid = user.Guid }; UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEntity); - if (result == null) throw new Exception("User update failed."); - Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result.GroupID.ToString()); - if (group == null) throw new Exception("Group not found."); - return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; - } - - private static UserLocalEntity GetUserLocalEntity(UserLocalEntity userLocalEntity) + if (result == null) throw new Exception("Пользователь не обновлен."); + Group? group = GetAllGroups().FirstOrDefault(it => { - return userLocalEntity; + bool v = it.Id == result.GroupID.ToString(); + return v; + }); + if (group == null) throw new Exception("Группа не обновлена."); + + return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; } + private List GetAllGroups() +{ + return new List(); +} + public User FindUserByGuid(Guid userGuid) { var user = _repositoryUserImpl.GetAllUsersList().FirstOrDefault(u => u.Guid == userGuid); - if (user == null) throw new Exception("User not found."); - var group = RepositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == user.GroupID); + if (user == null) throw new Exception("Пользователь не найден."); + var group = RepositoryGroupImpl.AllGroup.FirstOrDefault(g => g.Id == user.GroupID); return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; } - public List GetAllGroup() - { - return new List(); - } + public List AllGroup => new List(); + List IGroupRepository.AllGroup => throw new NotImplementedException(); - List IGroupRepository.GetAllGroup() + IEnumerable IGroupRepository.AllGroups() { - throw new NotImplementedException(); + return (IEnumerable)((IGroupRepository)_repositoryUserImpl).GetAllGroups(); } public bool RemoveGroupById(int groupID) @@ -74,12 +72,12 @@ namespace Zurnal.Domain.UseCase throw new NotImplementedException(); } - public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup) + public bool UpdateGroupById(int groupID, GroupDao updatedGroup) { throw new NotImplementedException(); } - public bool AddGroup(GroupLocalEntity newGroup) + public bool AddGroup(GroupDao newGroup) { throw new NotImplementedException(); } @@ -89,17 +87,17 @@ namespace Zurnal.Domain.UseCase throw new NotImplementedException(); } - public System.Text.RegularExpressions.Group GetGroupById(int id) + public GroupDao GetGroupById(int id) { throw new NotImplementedException(); } - public IEnumerable GetAllGroups() + IEnumerable IGroupRepository.GetAllGroups() { throw new NotImplementedException(); } - public void UpdateGroup(System.Text.RegularExpressions.Group group) + public void UpdateGroup(GroupDao group) { throw new NotImplementedException(); }