61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
|
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();
|
||
|
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUser()
|
||
|
.Join(_repositoryGroupImpl.GetAllGroup(),
|
||
|
user => user.GroupId,
|
||
|
group => group.Id,
|
||
|
(user, group) =>
|
||
|
new User { FIO = user.FIO,
|
||
|
Guid = user.UserGuid,
|
||
|
GroupId = new Group{Id = group.Id, Name = group.Name}}
|
||
|
).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,
|
||
|
Guid = _repositoryUserImpl.GetUserById(userId).UserGuid,
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|