55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
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 SQLUserRepositoryImpl _repositoryUserImpl;
|
|
private readonly IGroupRepository _repositoryGroupImpl;
|
|
|
|
public UserUseCase(SQLUserRepositoryImpl repositoryImpl, SQLGroupRepositoryImpl repositoryGroupImpl)
|
|
{
|
|
_repositoryUserImpl = repositoryImpl;
|
|
_repositoryGroupImpl = repositoryGroupImpl;
|
|
}
|
|
|
|
private List<GroupDao> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
|
|
.Select(it => new GroupDao { Id = it.Id, Name = it.Name}).ToList();
|
|
public List<UserDao> GetAllUsers() => _repositoryUserImpl.GetAllUser()
|
|
.Join(_repositoryGroupImpl.GetAllGroups(),
|
|
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);
|
|
}
|
|
}
|
|
} |