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 { public class GroupUseCase:IGroupUseCase { private IGroupRepository _repositoryGroupImpl; public GroupUseCase(IGroupRepository groupRepository) { _repositoryGroupImpl = groupRepository; } public List GetAllGroups() => _repositoryGroupImpl.GetAllGroup() .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); public Group UpdateGroupName(Group group) { 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 }; } public bool RemoveGroupById(int groupId) { return _repositoryGroupImpl.RemoveGroupById(groupId); } public bool CreateGroup(Group group) { GroupLocalEntity? groupLocalEntity = new GroupLocalEntity{Id = group.Id, Name = group.Name}; _repositoryGroupImpl.CreateGroup(groupLocalEntity); if (groupLocalEntity != null) return false; return true; } 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 }; } } }