61 lines
1.6 KiB
C#
61 lines
1.6 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
|
|||
|
{
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool AddGroup(string Name)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
}
|