2024-11-13 09:00:26 +00:00
|
|
|
|
using data.Exception;
|
2024-11-11 09:07:11 +00:00
|
|
|
|
using data.LocalData;
|
|
|
|
|
using data.RemoteData.RemoteDataBase.DAO;
|
|
|
|
|
using data.Repository;
|
|
|
|
|
using domain.Models;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
public class GroupRepositoryImpl : IGroupRepository
|
|
|
|
|
{
|
|
|
|
|
private List<GroupLocalEntity> _groups = LocalStaticData.groups;
|
|
|
|
|
|
|
|
|
|
public GroupLocalEntity? GetGroupById(int groupId)
|
|
|
|
|
{
|
|
|
|
|
return _groups.FirstOrDefault(g => g.Id == groupId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для получения всех групп
|
|
|
|
|
public List<GroupLocalEntity> GetAllGroup() => _groups;
|
|
|
|
|
|
|
|
|
|
// Метод для добавления новой группы
|
|
|
|
|
public bool AddGroup(GroupLocalEntity group)
|
|
|
|
|
{
|
|
|
|
|
if (_groups.Any(g => g.Id == group.Id))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
group.Id = _groups.Any() ? _groups.Max(g => g.Id) + 1 : 1;
|
|
|
|
|
_groups.Add(group);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для обновления существующей группы
|
|
|
|
|
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
|
|
|
|
|
{
|
|
|
|
|
var existingGroup = GetGroupById(groupID);
|
|
|
|
|
if (existingGroup == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
existingGroup.Name = updatedGroup.Name;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool RemoveGroupById(int groupID)
|
|
|
|
|
{
|
|
|
|
|
var existingGroup = GetGroupById(groupID);
|
|
|
|
|
if (existingGroup == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
_groups.Remove(existingGroup);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|