Demo/Domain/UseCase/GroupUseCase.cs
2024-10-21 12:38:07 +03:00

57 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Demo.Domain.Models;
using Demo.Data.Repository;
namespace Demo.Domain.UseCase
{
public class GroupUseCase
{
private readonly IUserRepository _repositoryUserImpl;
private readonly IGroupRepository _repositoryGroupImpl;
public GroupUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl)
{
_repositoryGroupImpl = repositoryGroupImpl;
_repositoryUserImpl = repositoryUserImpl;
}
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
.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.CreateGroup(groupLocalEntity);
if (groupLocalEntity != null) return false;
return true;
}
public Group UpdateGroup(Group group)
{
GroupLocalEntity groupLocalEntity = new GroupLocalEntity
{
ID = group.ID,
Name = group.Name
};
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity);
if (result == null)
{
throw new Exception("Не удалось обновить пользователя: пользователь не найден.");
}
return new Group
{
ID = result.ID,
Name = result.Name
};
}
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};
}
}
}