Demo/Domain/UseCase/GroupUseCase.cs

45 lines
1.6 KiB
C#
Raw Normal View History

2024-10-17 11:46:19 +00:00
using Demo.Domain.Models;
using Demo.Data.Repository;
namespace Demo.Domain.UseCase
{
public class GroupUseCase
{
private GroupRepositoryImpl _repositoryGroupImpl;
private UserRepositoryImpl _repositoryUserImpl;
public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl, UserRepositoryImpl repositoryUserImpl)
{
_repositoryGroupImpl = repositoryGroupImpl;
_repositoryUserImpl = repositoryUserImpl;
}
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups
.Select(it => new Group{ID = it.ID, Name = it.Name}).ToList();
public bool CreateNewGroup(Group group){
GroupLocalEntity? groupLocalEntity = new GroupLocalEntity{ID = group.ID, Name = group.Name};
_repositoryGroupImpl.CreateNewGroup(groupLocalEntity);
if (groupLocalEntity != null) return false;
return true;
}
public Group UpdateUser(Group group)
{
GroupLocalEntity groupLocalEntity = new GroupLocalEntity
{
ID = group.ID,
Name = group.Name
};
GroupLocalEntity? result = _repositoryGroupImpl.UpdateUserById(groupLocalEntity);
if (result == null)
{
throw new Exception("Не удалось обновить пользователя: пользователь не найден.");
}
return new Group
{
ID = result.ID,
Name = result.Name
};
}
}
}