Raspisanie/Zurnal/Domain/UseCase/UserUseCase.cs

119 lines
4.0 KiB
C#
Raw Normal View History

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 06:57:09 +00:00
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)));
}
private object NewMethod()
{
return RepositoryGroupImpl.GetAllGroup()
.Select(it => new Group { Id = it.Id, Name = it.Name });
}
2024-10-21 11:56:16 +00:00
2024-11-01 06:57:09 +00:00
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsersList()
2024-10-21 11:56:16 +00:00
.Join(RepositoryGroupImpl.GetAllGroup(),
user => user.GroupID,
group => group.Id,
(user, group) =>
new User { FIO = user.FIO,
Guid = user.Guid,
2024-10-25 09:20:05 +00:00
Group = new Group { Id = group.Id, Name = group.Name } }
).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 06:57:09 +00:00
public User UpdateUser(User user, Guid 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.");
2024-10-31 11:37:45 +00:00
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-11-01 06:57:09 +00:00
private static UserLocalEntity GetUserLocalEntity(UserLocalEntity userLocalEntity)
2024-10-25 09:20:05 +00:00
{
2024-10-31 11:37:45 +00:00
return userLocalEntity;
2024-10-21 11:56:16 +00:00
}
2024-10-25 09:20:05 +00:00
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);
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
}
2024-10-31 11:37:45 +00:00
2024-11-01 06:57:09 +00:00
public List<Group> GetAllGroup()
{
return new List<Group>();
}
List<GroupLocalEntity> IGroupRepository.GetAllGroup()
2024-10-31 11:37:45 +00:00
{
throw new NotImplementedException();
}
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 06:57:09 +00:00
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
2024-10-31 11:37:45 +00:00
{
throw new NotImplementedException();
}
2024-11-01 06:57:09 +00:00
public bool AddGroup(GroupLocalEntity 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 06:57:09 +00:00
public System.Text.RegularExpressions.Group GetGroupById(int id)
2024-10-31 11:37:45 +00:00
{
throw new NotImplementedException();
}
2024-11-01 06:57:09 +00:00
public IEnumerable<System.Text.RegularExpressions.Group> GetAllGroups()
2024-10-31 11:37:45 +00:00
{
throw new NotImplementedException();
}
2024-11-01 06:57:09 +00:00
public void UpdateGroup(System.Text.RegularExpressions.Group 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
}