xxxproject/Demo/Domain/UseCase/GroupUseCase.cs

44 lines
1.2 KiB
C#
Raw Normal View History

2024-10-30 09:11:19 +00:00
using Demo.Data.Entity;
using Demo.Data.LocalData;
2024-10-18 09:51:43 +00:00
using Demo.Data.Repository;
using Demo.domain.Models;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Domain.UseCase
{
public class GroupUseCase
{
2024-10-30 09:11:19 +00:00
private IGroupRepository _repositoryGroupImpl;
2024-10-18 09:51:43 +00:00
2024-10-30 09:11:19 +00:00
public GroupUseCase(IGroupRepository repositoryGroupImpl)
2024-10-18 09:51:43 +00:00
{
_repositoryGroupImpl = repositoryGroupImpl;
}
2024-10-21 12:42:07 +00:00
public bool RemoveGroupById(int groupID)
{
2024-10-30 09:11:19 +00:00
var group = _repositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == groupID);
2024-10-21 12:42:07 +00:00
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-23 09:42:17 +00:00
2024-10-21 12:42:07 +00:00
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
}
}
}