Demo/Domain/UseCase/GroupUseCase.cs

54 lines
1.8 KiB
C#
Raw Normal View History

2024-10-28 03:24:11 +00:00
using Demo.Domain.Models;
using Demo.Data.Repository;
namespace Demo.Domain.UseCase
{
2024-10-28 03:24:11 +00:00
public class GroupUseCase : IGroupUseCase
{
2024-10-28 03:24:11 +00:00
private readonly IUserRepository _repositoryUserImpl;
2024-10-24 20:41:31 +00:00
private readonly IGroupRepository _repositoryGroupImpl;
2024-10-28 03:24:11 +00:00
public GroupUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl)
{
2024-10-28 03:24:11 +00:00
_repositoryGroupImpl = repositoryGroupImpl;
_repositoryUserImpl = repositoryUserImpl;
}
2024-10-21 10:38:39 +00:00
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
2024-10-28 03:24:11 +00:00
.Select(it => new Group{ID = it.ID, Name = it.Name}).ToList();
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-28 03:24:11 +00:00
public bool CreateGroup(string Name){
_repositoryGroupImpl.CreateGroup(Name);
return true;
}
2024-10-28 03:24:11 +00:00
public Group UpdateGroup(Group group)
{
2024-10-17 12:35:14 +00:00
GroupLocalEntity groupLocalEntity = new GroupLocalEntity
{
2024-10-28 03:24:11 +00:00
ID = group.ID,
2024-10-17 12:35:14 +00:00
Name = group.Name
};
2024-10-28 03:24:11 +00:00
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity);
2024-10-17 12:35:14 +00:00
if (result == null)
{
2024-10-28 03:24:11 +00:00
throw new Exception("Не удалось обновить пользователя: пользователь не найден.");
2024-10-17 12:35:14 +00:00
}
return new Group
{
2024-10-28 03:24:11 +00:00
ID = result.ID,
2024-10-17 12:35:14 +00:00
Name = result.Name
};
}
2024-10-28 03:24:11 +00:00
public bool RemoveGroupByID(int userID) {
return _repositoryGroupImpl.RemoveGroupByID(userID);
2024-10-21 10:38:39 +00:00
}
}
2024-10-28 03:24:11 +00:00
}