presence/Demo/Data/Repository/GroupRepositoryImpl.cs
2024-10-25 11:47:11 +03:00

111 lines
2.7 KiB
C#

using Demo.Data.Exceptions;
using Demo.Data.LocalData;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.Data.Repository;
using Demo.domain.Models;
using System.Collections.Generic;
using System.Linq;
public class GroupRepositoryImpl: IGroupRepository
{
private List<GroupLocalEntity> _groups = LocalStaticData.groups;
public GroupLocalEntity? GetGroupById(int groupId)
{
foreach (var group in _groups)
{
if (group.Id == groupId)
{
return group;
}
}
return null;
}
// Метод для получения всех групп
public List<GroupLocalEntity> GetAllGroups() => _groups;
// Метод для добавления новой группы
public void AddGroup(GroupLocalEntity group)
{
group.Id = _groups.Any() ? _groups.Max(g => g.Id) + 1 : 1;
_groups.Add(group);
}
// Метод для обновления существующей группы
public void UpdateGroup(GroupLocalEntity group)
{
var existingGroup = GetGroupById(group.Id);
if (existingGroup == null) throw new GroupNotFoundException(group.Id);
}
public void RemoveGroupById(GroupLocalEntity group)
{
var existingGroup = GetGroupById(group.Id);
if (existingGroup == null) throw new GroupNotFoundException(group.Id);
if (_groups.Contains(existingGroup))
{
_groups.Remove(existingGroup);
}
}
public List<GroupLocalEntity> GetAllGroup()
{
throw new NotImplementedException();
}
public bool RemoveGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
{
throw new NotImplementedException();
}
bool IGroupRepository.AddGroup(GroupLocalEntity newGroup)
{
throw new NotImplementedException();
}
public List<GroupDao> GetAllGroupDao()
{
throw new NotImplementedException();
}
public bool RemoveGroupByIdDao(int groupID)
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupDao updatedGroup)
{
throw new NotImplementedException();
}
public GroupDao GetGroupByIdDao(int groupID)
{
throw new NotImplementedException();
}
public bool AddGroup(GroupDao newGroup)
{
throw new NotImplementedException();
}
public bool UpdateGroupByIdDao(int groupID, GroupDao updatedGroup)
{
throw new NotImplementedException();
}
public bool AddGroupDao(GroupDao newGroup)
{
throw new NotImplementedException();
}
}