Demo/Domain/UseCase/GroupUseCase.cs
2024-10-17 15:35:14 +03:00

53 lines
1.4 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? result = _repositoryGroupImpl.UpdateGroupName(groupLocalEntity);
if (result == null)
{
throw new Exception("");
}
return new Group
{
Id = result.Id,
Name = result.Name
};
}
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;
}
}
}