63 lines
1.7 KiB
C#
63 lines
1.7 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:IGroupUseCase
|
|
{
|
|
|
|
private readonly IGroupRepository _repositoryGroupImpl;
|
|
|
|
public GroupUseCase(IGroupRepository groupRepository, IUserRepository repositoryUserImpl)
|
|
{
|
|
_repositoryGroupImpl = groupRepository;
|
|
}
|
|
|
|
public List<Group> 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(string Name) {
|
|
|
|
_repositoryGroupImpl.CreateGroup(Name);
|
|
return true;
|
|
}
|
|
|
|
public Group GetGroupById(int groupId) {
|
|
|
|
GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupId);
|
|
if (groupLocalEntity == null) throw new Exception("bello");
|
|
return new Group{Id = groupId, Name = groupLocalEntity.Name};
|
|
}
|
|
}
|
|
}
|