2024-10-14 11:51:48 +00:00
|
|
|
|
using Demo.Data.LocalData;
|
|
|
|
|
using Demo.domain.Models;
|
|
|
|
|
using System.Collections.Generic;
|
2024-10-21 12:42:07 +00:00
|
|
|
|
using System.Linq;
|
2024-10-14 11:51:48 +00:00
|
|
|
|
|
|
|
|
|
namespace Demo.Data.Repository
|
|
|
|
|
{
|
2024-10-21 12:42:07 +00:00
|
|
|
|
public class GroupRepositoryImpl : IGroupRepository
|
2024-10-14 11:51:48 +00:00
|
|
|
|
{
|
2024-10-21 12:42:07 +00:00
|
|
|
|
public List<GroupLocalEntity> GetAllGroups { get; private set; }
|
|
|
|
|
|
|
|
|
|
public GroupRepositoryImpl()
|
|
|
|
|
{
|
2024-10-18 09:51:43 +00:00
|
|
|
|
GetAllGroups = LocalStaticData.groups;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 12:42:07 +00:00
|
|
|
|
public List<GroupLocalEntity> GetAllGroup()
|
|
|
|
|
{
|
|
|
|
|
return GetAllGroups;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GroupLocalEntity GetGroupById(int groupID)
|
|
|
|
|
{
|
|
|
|
|
return GetAllGroups.FirstOrDefault(g => g.Id == groupID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool RemoveGroupById(int groupID)
|
2024-10-18 09:51:43 +00:00
|
|
|
|
{
|
2024-10-21 12:42:07 +00:00
|
|
|
|
var group = GetAllGroups.FirstOrDefault(g => g.Id == groupID);
|
|
|
|
|
if (group != null)
|
|
|
|
|
{
|
|
|
|
|
GetAllGroups.Remove(group);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
|
|
|
|
|
{
|
|
|
|
|
var existingGroup = GetAllGroups.FirstOrDefault(g => g.Id == groupID);
|
|
|
|
|
if (existingGroup != null)
|
|
|
|
|
{
|
|
|
|
|
existingGroup.Name = updatedGroup.Name;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool AddGroup(GroupLocalEntity newGroup)
|
|
|
|
|
{
|
|
|
|
|
// Проверяем, существует ли группа с таким же ID
|
|
|
|
|
if (GetAllGroups.Any(g => g.Id == newGroup.Id))
|
|
|
|
|
{
|
|
|
|
|
return false; // Группа с таким ID уже существует
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetAllGroups.Add(newGroup); // Добавляем новую группу
|
|
|
|
|
return true; // Успешное добавление
|
2024-10-18 09:51:43 +00:00
|
|
|
|
}
|
2024-10-14 11:51:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|