Raspisanie/Zurnal/Domain/UseCase/UserUseCase.cs

66 lines
2.2 KiB
C#
Raw Permalink Normal View History

2024-10-23 08:14:10 +00:00
using Zurnal.Data.Repository;
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-02 09:07:18 +00:00
public List<UserDao> 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) =>
2024-11-02 09:07:18 +00:00
new UserDao { FIO = user.FIO,
UserGuid = user.Guid,
Group = new GroupDao { Id = group.Id, GroupName = group.GroupName },
GroupID = group.Id }
).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-02 09:07:18 +00:00
public IEnumerable<GroupDao> GetAllGroups()
2024-11-01 07:49:39 +00:00
{
2024-11-02 09:07:18 +00:00
return RepositoryGroupImpl.AllGroup;
2024-11-01 07:49:39 +00:00
}
2024-11-02 09:07:18 +00:00
public UserDao FindUserByGuid(Guid userGuid)
{
var user = _repositoryUserImpl.GetAllUsersList().FirstOrDefault(u => u.Guid == userGuid);
if (user == null)
{
Console.WriteLine("Пользователь не найден.");
return null;
}
GroupDao group = RepositoryGroupImpl.AllGroup.FirstOrDefault(g => g.Id == user.GroupID);
if (group == null)
{
Console.WriteLine("Группа не найдена.");
return null;
}
return new UserDao { FIO = user.FIO, UserGuid = user.Guid, Group = group, GroupID = group.Id };
}
2024-10-31 11:37:45 +00:00
2024-11-02 09:07:18 +00:00
public List<GroupDao> AllGroup => RepositoryGroupImpl.AllGroup.ToList();
2024-11-01 07:49:39 +00:00
List<GroupDao> IGroupRepository.AllGroup => throw new NotImplementedException();
2024-11-01 06:57:09 +00:00
internal class UserLocalEntity
{
public string FIO { get; set; }
2024-11-02 07:59:27 +00:00
public int GroupID { get; set; }
2024-11-01 06:57:09 +00:00
public Guid Guid { get; set; }
}
2024-10-31 11:37:45 +00:00
}
2024-10-25 09:20:05 +00:00
}