61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using Demo.Data.Exceptions;
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
|
using Demo.Data.Repository;
|
|
using Demo.domain.Models;
|
|
|
|
namespace Demo.Domain.UseCase
|
|
{
|
|
public class UserUseCase
|
|
{
|
|
|
|
|
|
private readonly IUserRepository _repositoryUserImpl;
|
|
private readonly IGroupRepository _repositoryGroupImpl;
|
|
|
|
public UserUseCase(IUserRepository repositoryImpl, IGroupRepository repositoryGroupImpl)
|
|
{
|
|
_repositoryUserImpl = repositoryImpl;
|
|
_repositoryGroupImpl = repositoryGroupImpl;
|
|
}
|
|
|
|
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUser()
|
|
.Join(_repositoryGroupImpl.GetAllGroup(),
|
|
user => user.GroupId,
|
|
group => group.Id,
|
|
(user, group) =>
|
|
new User
|
|
{
|
|
FIO = user.FIO,
|
|
Id = user.UserId,
|
|
GroupId = new Group { Id = group.Id, Name = group.Name }
|
|
}
|
|
).ToList();
|
|
|
|
|
|
public bool RemoveUserById(int userId)
|
|
{
|
|
return _repositoryUserImpl.RemoveUserById(userId);
|
|
}
|
|
public bool UpdateUser(User user)
|
|
{
|
|
UserDao userDao = new UserDao { FIO = user.FIO, GroupId = user.GroupId.Id };
|
|
return _repositoryUserImpl.UpdateUser(userDao);
|
|
}
|
|
|
|
public User GetUserById(int userId)
|
|
{
|
|
return new User
|
|
{
|
|
FIO = _repositoryUserImpl.GetUserById(userId).FIO,
|
|
Id = _repositoryUserImpl.GetUserById(userId).UserId,
|
|
GroupId = new Group { Id = _repositoryUserImpl.GetUserById(userId).GroupId, Name = _repositoryGroupImpl.GetGroupById(userId).Name }
|
|
};
|
|
}
|
|
|
|
public bool UpdateUserById(int userId, String fio, int groupId)
|
|
{
|
|
UserDao userDao = new UserDao { FIO = fio, GroupId = groupId };
|
|
return _repositoryUserImpl.UpdateUser(userDao);
|
|
}
|
|
}
|
|
} |