2024-11-16 14:13:06 +00:00
|
|
|
using domain.Models.ResponseModels;
|
2024-11-16 12:02:17 +00:00
|
|
|
using presence.data.LocalData.Entity;
|
|
|
|
using presence.data.RemoteData.RemoteDataBase.DAO;
|
|
|
|
using presence.data.Repository;
|
|
|
|
using presence.domain.Models;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace presence.domain.UseCase
|
|
|
|
{
|
|
|
|
public class UserUseCase
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IUserRepository _repositoryUserImpl;
|
|
|
|
private readonly IGroupRepository _repositoryGroupImpl;
|
|
|
|
|
|
|
|
public UserUseCase(IUserRepository repositoryImpl, IGroupRepository repositoryGroupImpl)
|
|
|
|
{
|
|
|
|
_repositoryUserImpl = repositoryImpl;
|
|
|
|
_repositoryGroupImpl = repositoryGroupImpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
|
|
|
|
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
|
2024-11-16 14:13:06 +00:00
|
|
|
public List<UserResponse> GetAllUsers() => _repositoryUserImpl.GetAllUser()
|
2024-11-16 12:02:17 +00:00
|
|
|
.Join(_repositoryGroupImpl.GetAllGroup(),
|
|
|
|
user => user.GroupId,
|
|
|
|
group => group.Id,
|
|
|
|
(user, group) =>
|
2024-11-16 14:13:06 +00:00
|
|
|
new UserResponse { FIO = user.FIO,
|
|
|
|
Id = user.UserId,
|
|
|
|
Group = new GroupResponse{Id = group.Id, Name = group.Name}}
|
2024-11-16 12:02:17 +00:00
|
|
|
).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,
|
2024-11-16 14:13:06 +00:00
|
|
|
Id = _repositoryUserImpl.GetUserById(userId).UserId,
|
2024-11-16 12:02:17 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|