pr1/presence/domain/UseCase/UserUseCase.cs

61 lines
1.9 KiB
C#
Raw Normal View History

2024-11-17 16:24:01 +00:00
using Demo.Data.Exceptions;
2024-12-05 09:30:01 +00:00
using Demo.Data.RemoteData.RemoteDataBase.DAO;
2024-11-17 16:24:01 +00:00
using Demo.Data.Repository;
2024-10-19 21:12:06 +00:00
using Demo.domain.Models;
namespace Demo.Domain.UseCase
{
public class UserUseCase
{
2024-12-19 17:36:57 +00:00
2024-11-17 16:24:01 +00:00
private readonly IUserRepository _repositoryUserImpl;
private readonly IGroupRepository _repositoryGroupImpl;
2024-10-19 21:12:06 +00:00
2024-11-17 16:24:01 +00:00
public UserUseCase(IUserRepository repositoryImpl, IGroupRepository repositoryGroupImpl)
2024-10-19 21:12:06 +00:00
{
_repositoryUserImpl = repositoryImpl;
_repositoryGroupImpl = repositoryGroupImpl;
}
2024-12-19 17:36:57 +00:00
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUser()
2024-11-17 16:24:01 +00:00
.Join(_repositoryGroupImpl.GetAllGroup(),
2024-12-19 17:36:57 +00:00
user => user.GroupId,
2024-11-17 16:24:01 +00:00
group => group.Id,
(user, group) =>
new User
{
FIO = user.FIO,
2024-12-19 17:36:57 +00:00
Id = user.UserId,
GroupId = new Group { Id = group.Id, Name = group.Name }
2024-10-19 21:39:57 +00:00
}
2024-12-19 17:36:57 +00:00
).ToList();
2024-11-17 16:24:01 +00:00
2024-12-05 09:30:01 +00:00
2024-12-19 17:36:57 +00:00
public bool RemoveUserById(int userId)
2024-11-17 16:24:01 +00:00
{
2024-12-19 17:36:57 +00:00
return _repositoryUserImpl.RemoveUserById(userId);
2024-11-17 16:24:01 +00:00
}
2024-12-19 17:36:57 +00:00
public bool UpdateUser(User user)
2024-11-17 16:24:01 +00:00
{
2024-12-19 17:36:57 +00:00
UserDao userDao = new UserDao { FIO = user.FIO, GroupId = user.GroupId.Id };
return _repositoryUserImpl.UpdateUser(userDao);
}
2024-11-17 16:24:01 +00:00
2024-12-19 17:36:57 +00:00
public User GetUserById(int userId)
{
2024-11-17 16:24:01 +00:00
return new User
{
2024-12-19 17:36:57 +00:00
FIO = _repositoryUserImpl.GetUserById(userId).FIO,
Id = _repositoryUserImpl.GetUserById(userId).UserId,
GroupId = new Group { Id = _repositoryUserImpl.GetUserById(userId).GroupId, Name = _repositoryGroupImpl.GetGroupById(userId).Name }
2024-11-17 16:24:01 +00:00
};
2024-10-19 21:12:06 +00:00
}
2024-12-19 17:36:57 +00:00
public bool UpdateUserById(int userId, String fio, int groupId)
2024-12-05 09:30:01 +00:00
{
2024-12-19 17:36:57 +00:00
UserDao userDao = new UserDao { FIO = fio, GroupId = groupId };
return _repositoryUserImpl.UpdateUser(userDao);
2024-12-05 09:30:01 +00:00
}
2024-10-19 21:12:06 +00:00
}
2024-12-19 17:36:57 +00:00
}