Raspisanie/Zurnal/Domain/UseCase/GroupUseCase.cs
2024-11-07 14:31:00 +03:00

79 lines
2.1 KiB
C#

using Zurnal.Data.Repository;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Domain.UseCase
{
public class GroupUseCase : IGroupRepository
{
private readonly IGroupRepository _repository;
private List<GroupDao> _groups = new List<GroupDao>();
public List<GroupDao> AllGroup => _groups;
private UserRepositoryImpl _repositoryUserImpl;
private GroupRepositoryImpl _repositoryGroupImpl;
public List<GroupDao> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new GroupDao { Id = it.Id, GroupName = it.GroupName }).ToList();
public GroupUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
{
_repositoryUserImpl = repositoryImpl;
_repositoryGroupImpl = repositoryGroupImpl;
}
public void AddGroup(GroupDao group)
{
_repositoryGroupImpl.AddGroup(group: group);
}
public void UpdateGroupName(int groupId, string newName)
{
_repositoryGroupImpl.UpdateGroupName(groupId, newName);
}
public IEnumerable<GroupDao> AllGroups()
{
throw new NotImplementedException();
}
public bool RemoveGroupById(int groupID)
{
var group = _repositoryGroupImpl.FindGroupById(groupID);
if (group == null)
{
return false;
}
_repositoryGroupImpl.DeleteGroup(groupID);
return true;
}
IEnumerable<GroupDao> IGroupRepository.GetAllGroups()
{
return _repositoryGroupImpl.GetAllGroups()
.Select(it => new GroupDao { Id = it.Id, GroupName = it.GroupName, Users = it.Users })
.ToList();
}
public GroupDao GetGroupById(int id)
{
return _groups.FirstOrDefault(g => g.Id == id);
}
public List<GroupResponse> getAllGroup(){
return _repository.GetAllGroup().Select(group =>
new GroupResponse {
Id = group.Id,
Name = group.Name
}
).ToList();
}
public List<GroupLocalEntity> GetAllGroup()
{
throw new NotImplementedException();
}
}
}