2024-10-17 16:08:02 +00:00
|
|
|
using Posechaemost.Data.LocalData.Entity;
|
2024-11-06 04:10:09 +00:00
|
|
|
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
|
2024-10-17 16:08:02 +00:00
|
|
|
using Posechaemost.Data.Repository;
|
|
|
|
using Posechaemost.Domain.Models;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace Posechaemost.Domain.UseCase
|
|
|
|
{
|
|
|
|
public class UserUseCase
|
|
|
|
{
|
2024-10-23 07:06:56 +00:00
|
|
|
|
2024-11-11 20:02:21 +00:00
|
|
|
|
|
|
|
private readonly IUserRepository _repositoryUserImpl;
|
2024-10-23 07:06:56 +00:00
|
|
|
private readonly IGroupRepository _repositoryGroupImpl;
|
2024-10-17 16:08:02 +00:00
|
|
|
|
2024-11-11 20:02:21 +00:00
|
|
|
public UserUseCase(IUserRepository repositoryImpl, IGroupRepository repositoryGroupImpl)
|
2024-10-17 16:08:02 +00:00
|
|
|
{
|
|
|
|
_repositoryUserImpl = repositoryImpl;
|
|
|
|
_repositoryGroupImpl = repositoryGroupImpl;
|
|
|
|
}
|
|
|
|
|
2024-11-11 20:02:21 +00:00
|
|
|
private List<GroupDao> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
|
2024-11-06 04:10:09 +00:00
|
|
|
.Select(it => new GroupDao { Id = it.Id, Name = it.Name}).ToList();
|
|
|
|
public List<UserDao> GetAllUsers() => _repositoryUserImpl.GetAllUser()
|
2024-11-11 20:02:21 +00:00
|
|
|
.Join(_repositoryGroupImpl.GetAllGroup(),
|
2024-11-06 04:10:09 +00:00
|
|
|
user => user.GroupId,
|
2024-10-17 16:08:02 +00:00
|
|
|
group => group.Id,
|
|
|
|
(user, group) =>
|
2024-11-06 04:10:09 +00:00
|
|
|
new UserDao { FIO = user.FIO,
|
|
|
|
UserId = user.UserId,
|
|
|
|
GroupId = group.Id }
|
2024-10-17 16:08:02 +00:00
|
|
|
).ToList();
|
|
|
|
|
|
|
|
|
2024-11-06 04:10:09 +00:00
|
|
|
public bool RemoveUserById(int userId) {
|
|
|
|
return _repositoryUserImpl.RemoveUserById(userId);
|
2024-10-17 16:08:02 +00:00
|
|
|
}
|
2024-11-06 04:10:09 +00:00
|
|
|
public bool UpdateUser(UserDao user) {
|
|
|
|
UserDao userDao = new UserDao { FIO = user.FIO, GroupId = user.GroupId };
|
|
|
|
return _repositoryUserImpl.UpdateUser(userDao);
|
2024-10-17 16:08:02 +00:00
|
|
|
}
|
2024-10-18 06:47:43 +00:00
|
|
|
|
2024-11-06 04:10:09 +00:00
|
|
|
public UserDao GetUserById(int userId) {
|
|
|
|
return _repositoryUserImpl.GetUserById(userId);
|
2024-10-18 06:47:43 +00:00
|
|
|
}
|
2024-10-18 08:27:50 +00:00
|
|
|
|
2024-11-06 04:10:09 +00:00
|
|
|
public bool UpdateUserById(int userId, String fio, int groupId) {
|
|
|
|
UserDao userDao = new UserDao { FIO = fio, GroupId = groupId };
|
|
|
|
return _repositoryUserImpl.UpdateUser(userDao);
|
2024-10-18 08:27:50 +00:00
|
|
|
}
|
2024-10-17 16:08:02 +00:00
|
|
|
}
|
|
|
|
}
|