presence_new/domain/UseCase/UserUseCase.cs
2024-12-13 10:21:14 +03:00

60 lines
2.1 KiB
C#
Executable File

using domain.Models.ResponseModels;
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;
}
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUser()
.Join(_repositoryGroupImpl.GetAllGroup(),
user => user.GroupId,
group => group.Id,
(user, group) =>
new User { FIO = user.FIO,
Id = user.UserId,
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,
Id = _repositoryUserImpl.GetUserById(userId).UserId,
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);
}
}
}