76 lines
1.9 KiB
C#
76 lines
1.9 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 UpdateGroupById(int groupId, GroupLocalEntity updatedGroup)
|
|||
|
{
|
|||
|
var existingGroup = GetGroupById(groupId);
|
|||
|
if (existingGroup == null) throw new GroupNotFoundException(groupId);
|
|||
|
}
|
|||
|
|
|||
|
public void RemoveGroupById(int groupId)
|
|||
|
{
|
|||
|
var existingGroup = GetGroupById(groupId);
|
|||
|
if (existingGroup == null) throw new GroupNotFoundException(groupId);
|
|||
|
if (_groups.Contains(existingGroup))
|
|||
|
{
|
|||
|
_groups.Remove(existingGroup);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
List<GroupDao> IGroupRepository.GetAllGroups()
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
|
|||
|
public bool UpdateGroupById(int groupID, GroupDao updatedGroup)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
|
|||
|
GroupDao IGroupRepository.GetGroupById(int groupID)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
|
|||
|
public bool AddGroup(string Name)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
}
|