Demo/Domain/UseCase/GroupUseCase.cs

45 lines
1.5 KiB
C#

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
{
private GroupRepositoryImpl _repositoryGroupImpl;
public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl)
{
_repositoryGroupImpl = repositoryGroupImpl;
}
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups
.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? updatedGroupEntity = _repositoryGroupImpl.UpdateGroupName(groupLocalEntity);
if (updatedGroupEntity == null) throw new Exception("");
return new Group { Id = updatedGroupEntity.Id, Name = updatedGroupEntity.Name};
}
public Group CreateGroup(Group group) {
GroupLocalEntity? groupLocalEntity = new GroupLocalEntity { Id = group.Id, Name = group.Name};
GroupLocalEntity? createdGroupEntity = _repositoryGroupImpl.CreateGroup(groupLocalEntity);
if (createdGroupEntity == null) throw new Exception("");
return new Group { Id = createdGroupEntity.Id, Name = createdGroupEntity.Name};
}
}
}