Demo/Domain/UseCase/GroupUseCase.cs

65 lines
1.9 KiB
C#
Raw Normal View History

using Demo.Data.Repository;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.Domain.UseCase
{
2024-10-21 10:38:39 +00:00
public class GroupUseCase:IGroupUseCase
{
2024-10-21 10:38:39 +00:00
private IGroupRepository _repositoryGroupImpl;
2024-10-21 10:38:39 +00:00
public GroupUseCase(IGroupRepository groupRepository)
{
2024-10-21 10:38:39 +00:00
_repositoryGroupImpl = groupRepository;
}
2024-10-21 10:38:39 +00:00
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
public Group UpdateGroupName(Group group) {
2024-10-17 12:35:14 +00:00
GroupLocalEntity groupLocalEntity = new GroupLocalEntity
{
Id = group.Id,
Name = group.Name
};
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroupName(groupLocalEntity);
if (result == null)
{
throw new Exception("");
}
return new Group
{
Id = result.Id,
Name = result.Name
};
}
2024-10-21 10:38:39 +00:00
public bool RemoveGroupById(int groupId) {
return _repositoryGroupImpl.RemoveGroupById(groupId);
}
2024-10-17 12:35:14 +00:00
public bool CreateGroup(Group group) {
2024-10-17 12:35:14 +00:00
GroupLocalEntity? groupLocalEntity = new GroupLocalEntity{Id = group.Id, Name = group.Name};
_repositoryGroupImpl.CreateGroup(groupLocalEntity);
if (groupLocalEntity != null) return false;
return true;
}
2024-10-21 10:38:39 +00:00
public Group GetGroupById(int groupId) {
GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupId);
if (groupLocalEntity == null) throw new Exception("");
return new Group { Id = groupLocalEntity.Id, Name = groupLocalEntity.Name };
}
}
}