Demo/Domain/UseCase/UserUseCase.cs

55 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-06 04:10:09 +00:00
private readonly SQLUserRepositoryImpl _repositoryUserImpl;
2024-10-23 07:06:56 +00:00
private readonly IGroupRepository _repositoryGroupImpl;
2024-11-06 04:10:09 +00:00
public UserUseCase(SQLUserRepositoryImpl repositoryImpl, SQLGroupRepositoryImpl repositoryGroupImpl)
{
_repositoryUserImpl = repositoryImpl;
_repositoryGroupImpl = repositoryGroupImpl;
}
2024-11-06 04:10:09 +00:00
private List<GroupDao> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new GroupDao { Id = it.Id, Name = it.Name}).ToList();
public List<UserDao> GetAllUsers() => _repositoryUserImpl.GetAllUser()
2024-10-24 11:13:46 +00:00
.Join(_repositoryGroupImpl.GetAllGroups(),
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);
}
}
}