2024-10-17 11:46:19 +00:00
|
|
|
|
using Demo.Domain.Models;
|
|
|
|
|
using Demo.Data.Repository;
|
|
|
|
|
|
|
|
|
|
namespace Demo.Domain.UseCase
|
|
|
|
|
{
|
|
|
|
|
public class GroupUseCase
|
|
|
|
|
{
|
2024-10-21 09:38:07 +00:00
|
|
|
|
private readonly IUserRepository _repositoryUserImpl;
|
|
|
|
|
private readonly IGroupRepository _repositoryGroupImpl;
|
|
|
|
|
public GroupUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl)
|
2024-10-17 11:46:19 +00:00
|
|
|
|
{
|
|
|
|
|
_repositoryGroupImpl = repositoryGroupImpl;
|
|
|
|
|
_repositoryUserImpl = repositoryUserImpl;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 09:38:07 +00:00
|
|
|
|
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
|
2024-10-17 11:46:19 +00:00
|
|
|
|
.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};
|
2024-10-21 09:38:07 +00:00
|
|
|
|
_repositoryGroupImpl.CreateGroup(groupLocalEntity);
|
2024-10-17 11:46:19 +00:00
|
|
|
|
if (groupLocalEntity != null) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 12:13:34 +00:00
|
|
|
|
public Group UpdateGroup(Group group)
|
2024-10-17 11:46:19 +00:00
|
|
|
|
{
|
|
|
|
|
GroupLocalEntity groupLocalEntity = new GroupLocalEntity
|
|
|
|
|
{
|
|
|
|
|
ID = group.ID,
|
|
|
|
|
Name = group.Name
|
|
|
|
|
};
|
2024-10-17 12:13:34 +00:00
|
|
|
|
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity);
|
2024-10-17 11:46:19 +00:00
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Не удалось обновить пользователя: пользователь не найден.");
|
|
|
|
|
}
|
|
|
|
|
return new Group
|
|
|
|
|
{
|
|
|
|
|
ID = result.ID,
|
|
|
|
|
Name = result.Name
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-10-21 09:38:07 +00:00
|
|
|
|
|
|
|
|
|
public bool RemoveUserByGuid(Guid userGuid) {
|
|
|
|
|
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Group GetGroupById(int groupID)
|
|
|
|
|
{
|
|
|
|
|
GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupID);
|
|
|
|
|
if (groupLocalEntity == null) throw new Exception("bello");
|
|
|
|
|
return new Group{
|
|
|
|
|
ID = groupID, Name = groupLocalEntity.Name};
|
|
|
|
|
}
|
2024-10-17 11:46:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|