xxxproject/Demo/Domain/UseCase/GroupUseCase.cs
2024-10-23 12:42:17 +03:00

43 lines
1.2 KiB
C#

using Demo.Data.LocalData;
using Demo.Data.Repository;
using Demo.domain.Models;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Domain.UseCase
{
public class GroupUseCase
{
private GroupRepositoryImpl _repositoryGroupImpl;
public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl)
{
_repositoryGroupImpl = repositoryGroupImpl;
}
public bool RemoveGroupById(int groupID)
{
var group = _repositoryGroupImpl.GetAllGroups.FirstOrDefault(g => g.Id == groupID);
if (group != null)
{
_repositoryGroupImpl.RemoveGroupById(groupID);
return true;
}
return false;
}
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
.Select(it => new Group { Id = it.Id, Name = it.Name }).ToList();
public bool AddGroup(GroupLocalEntity group)
{
return _repositoryGroupImpl.AddGroup(group);
}
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
{
return _repositoryGroupImpl.UpdateGroupById(groupID, updatedGroup);
}
}
}