2024-10-23 08:14:10 +00:00
|
|
|
|
using Zurnal.Data.Repository;
|
2024-11-01 06:57:09 +00:00
|
|
|
|
using Zurnal.Date.Repository;
|
2024-10-23 08:14:10 +00:00
|
|
|
|
using Zurnal.domain.Models;
|
2024-11-01 07:49:39 +00:00
|
|
|
|
using Zurnal.RemaDateBase.DateDao;
|
2024-10-21 11:56:16 +00:00
|
|
|
|
|
2024-10-23 08:14:10 +00:00
|
|
|
|
namespace Zurnal.Domain.UseCase
|
2024-10-21 11:56:16 +00:00
|
|
|
|
{
|
2024-10-31 11:37:45 +00:00
|
|
|
|
public class UserUseCase : IGroupRepository
|
2024-10-21 11:56:16 +00:00
|
|
|
|
{
|
2024-10-25 09:20:05 +00:00
|
|
|
|
private readonly UserRepositoryImpl _repositoryUserImpl;
|
|
|
|
|
internal IGroupRepository RepositoryGroupImpl { get; }
|
2024-10-21 11:56:16 +00:00
|
|
|
|
|
2024-10-25 09:20:05 +00:00
|
|
|
|
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
|
2024-11-01 06:57:09 +00:00
|
|
|
|
{
|
|
|
|
|
_repositoryUserImpl = repositoryImpl;
|
|
|
|
|
RepositoryGroupImpl = (IGroupRepository?)(repositoryGroupImpl ?? throw new ArgumentNullException(nameof(repositoryGroupImpl)));
|
|
|
|
|
}
|
2024-10-21 11:56:16 +00:00
|
|
|
|
|
2024-11-01 06:57:09 +00:00
|
|
|
|
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsersList()
|
2024-11-01 07:49:39 +00:00
|
|
|
|
.Join(RepositoryGroupImpl.AllGroup,
|
2024-10-21 11:56:16 +00:00
|
|
|
|
user => user.GroupID,
|
|
|
|
|
group => group.Id,
|
|
|
|
|
(user, group) =>
|
|
|
|
|
new User { FIO = user.FIO,
|
|
|
|
|
Guid = user.Guid,
|
2024-11-01 07:49:39 +00:00
|
|
|
|
Group = new Group { Id = group.Id, Name = group.GroupName } }
|
2024-10-25 09:20:05 +00:00
|
|
|
|
).ToList();
|
2024-10-21 11:56:16 +00:00
|
|
|
|
|
2024-10-25 09:20:05 +00:00
|
|
|
|
public bool RemoveUserByGuid(Guid userGuid)
|
|
|
|
|
{
|
|
|
|
|
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
2024-10-21 11:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-01 07:49:39 +00:00
|
|
|
|
public User UpdateUser(User user, Group id)
|
2024-11-01 06:57:09 +00:00
|
|
|
|
{
|
|
|
|
|
UserLocalEntity userLocalEntity = new UserLocalEntity { FIO = user.FIO, GroupID = id, Guid = user.Guid };
|
|
|
|
|
UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEntity);
|
2024-11-01 07:52:05 +00:00
|
|
|
|
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 };
|
|
|
|
|
}
|
2024-10-25 09:20:05 +00:00
|
|
|
|
|
2024-11-01 07:49:39 +00:00
|
|
|
|
private List<Group> GetAllGroups()
|
|
|
|
|
{
|
|
|
|
|
return new List<Group>();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-25 09:20:05 +00:00
|
|
|
|
public User FindUserByGuid(Guid userGuid)
|
|
|
|
|
{
|
|
|
|
|
var user = _repositoryUserImpl.GetAllUsersList().FirstOrDefault(u => u.Guid == userGuid);
|
2024-11-01 07:49:39 +00:00
|
|
|
|
if (user == null) throw new Exception("Пользователь не найден.");
|
|
|
|
|
var group = RepositoryGroupImpl.AllGroup.FirstOrDefault(g => g.Id == user.GroupID);
|
2024-10-25 09:20:05 +00:00
|
|
|
|
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
|
|
|
|
|
}
|
2024-10-31 11:37:45 +00:00
|
|
|
|
|
2024-11-01 07:49:39 +00:00
|
|
|
|
public List<Group> AllGroup => new List<Group>();
|
|
|
|
|
List<GroupDao> IGroupRepository.AllGroup => throw new NotImplementedException();
|
2024-11-01 06:57:09 +00:00
|
|
|
|
|
2024-11-01 07:49:39 +00:00
|
|
|
|
IEnumerable<System.Text.RegularExpressions.Group> IGroupRepository.AllGroups()
|
2024-10-31 11:37:45 +00:00
|
|
|
|
{
|
2024-11-01 07:49:39 +00:00
|
|
|
|
return (IEnumerable<System.Text.RegularExpressions.Group>)((IGroupRepository)_repositoryUserImpl).GetAllGroups();
|
2024-10-31 11:37:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-01 06:57:09 +00:00
|
|
|
|
public bool RemoveGroupById(int groupID)
|
2024-10-31 11:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-01 07:49:39 +00:00
|
|
|
|
public bool UpdateGroupById(int groupID, GroupDao updatedGroup)
|
2024-10-31 11:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-01 07:49:39 +00:00
|
|
|
|
public bool AddGroup(GroupDao newGroup)
|
2024-10-31 11:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-01 06:57:09 +00:00
|
|
|
|
public void AddGroupFromRegex(System.Text.RegularExpressions.Group group)
|
2024-10-31 11:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-01 07:49:39 +00:00
|
|
|
|
public GroupDao GetGroupById(int id)
|
2024-10-31 11:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-01 07:49:39 +00:00
|
|
|
|
IEnumerable<GroupDao> IGroupRepository.GetAllGroups()
|
2024-10-31 11:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-01 07:49:39 +00:00
|
|
|
|
public void UpdateGroup(GroupDao group)
|
2024-10-31 11:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2024-10-25 09:20:05 +00:00
|
|
|
|
|
2024-11-01 06:57:09 +00:00
|
|
|
|
public void DeleteGroup(int id)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class UserLocalEntity
|
|
|
|
|
{
|
|
|
|
|
public string FIO { get; set; }
|
|
|
|
|
public Guid GroupID { get; set; }
|
|
|
|
|
public Guid Guid { get; set; }
|
|
|
|
|
}
|
2024-10-31 11:37:45 +00:00
|
|
|
|
}
|
2024-10-25 09:20:05 +00:00
|
|
|
|
}
|