xxxproject/Demo/Domain/UseCase/GroupUseCase.cs

43 lines
1.3 KiB
C#
Raw Normal View History

2024-10-18 09:51:43 +00:00
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;
}
2024-10-21 12:42:07 +00:00
public bool RemoveGroupById(int groupID)
{
var group = _repositoryGroupImpl.GetAllGroups.FirstOrDefault(g => g.Id == groupID);
if (group != null)
{
_repositoryGroupImpl.RemoveGroupById(groupID);
return true;
}
return false;
}
2024-10-18 09:51:43 +00:00
2024-10-21 12:42:07 +00:00
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
2024-10-18 09:51:43 +00:00
.Select(it => new Group { Id = it.Id, Name = it.Name }).ToList();
2024-10-21 12:42:07 +00:00
public bool AddGroup(GroupLocalEntity group)
2024-10-18 09:51:43 +00:00
{
2024-10-21 12:42:07 +00:00
// Если метод возвращает true, то группа добавлена успешно
return _repositoryGroupImpl.AddGroup(group);
2024-10-18 09:51:43 +00:00
}
2024-10-21 12:42:07 +00:00
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
2024-10-18 09:51:43 +00:00
{
2024-10-21 12:42:07 +00:00
return _repositoryGroupImpl.UpdateGroupById(groupID, updatedGroup);
2024-10-18 09:51:43 +00:00
}
}
}