Demo/Domain/UseCase/UserUseCase.cs

56 lines
1.9 KiB
C#
Executable File

using Posechaemost.Data.LocalData.Entity;
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
{
private readonly IUserRepository _repositoryUserImpl;
private readonly IGroupRepository _repositoryGroupImpl;
public UserUseCase(IUserRepository repositoryImpl, IGroupRepository repositoryGroupImpl)
{
_repositoryUserImpl = repositoryImpl;
_repositoryGroupImpl = repositoryGroupImpl;
}
private List<GroupDao> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
.Select(it => new GroupDao { Id = it.Id, Name = it.Name}).ToList();
public List<UserDao> GetAllUsers() => _repositoryUserImpl.GetAllUser()
.Join(_repositoryGroupImpl.GetAllGroup(),
user => user.GroupId,
group => group.Id,
(user, group) =>
new UserDao { FIO = user.FIO,
UserId = user.UserId,
GroupId = group.Id }
).ToList();
public bool RemoveUserById(int userId) {
return _repositoryUserImpl.RemoveUserById(userId);
}
public bool UpdateUser(UserDao user) {
UserDao userDao = new UserDao { FIO = user.FIO, GroupId = user.GroupId };
return _repositoryUserImpl.UpdateUser(userDao);
}
public UserDao GetUserById(int userId) {
return _repositoryUserImpl.GetUserById(userId);
}
public bool UpdateUserById(int userId, String fio, int groupId) {
UserDao userDao = new UserDao { FIO = fio, GroupId = groupId };
return _repositoryUserImpl.UpdateUser(userDao);
}
}
}