Demo/Domain/UseCase/UserUseCase.cs

56 lines
1.9 KiB
C#
Raw Normal View History

using Posechaemost.Data.LocalData.Entity;
2024-11-06 04:10:09 +00:00
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
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-11-11 20:02:21 +00:00
public UserUseCase(IUserRepository repositoryImpl, IGroupRepository repositoryGroupImpl)
{
_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,
group => group.Id,
(user, group) =>
2024-11-06 04:10:09 +00:00
new UserDao { FIO = user.FIO,
UserId = user.UserId,
GroupId = group.Id }
).ToList();
2024-11-06 04:10:09 +00:00
public bool RemoveUserById(int userId) {
return _repositoryUserImpl.RemoveUserById(userId);
}
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-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-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);
}
}
}