33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
|
using Posechaemost.Data.LocalData.Entity;
|
||
|
using Posechaemost.Data.Repository;
|
||
|
using Posechaemost.Domain.Models;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace Posechaemost.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 grou) {
|
||
|
GroupLocalEntity groupLocalEntity = new GroupLocalEntity {Id = grou.Id, Name = grou.Name};
|
||
|
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity);
|
||
|
if (result == null) throw new Exception("");
|
||
|
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.Id);
|
||
|
if (group == null) throw new Exception("");
|
||
|
return new Group {Id = group.Id, Name = group.Name};
|
||
|
}
|
||
|
}
|
||
|
}
|