xxxproject/Demo/Data/Repository/GroupRepositoryImpl.cs
2024-10-21 15:42:07 +03:00

62 lines
1.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Demo.Data.LocalData;
using Demo.domain.Models;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Data.Repository
{
public class GroupRepositoryImpl : IGroupRepository
{
public List<GroupLocalEntity> GetAllGroups { get; private set; }
public GroupRepositoryImpl()
{
GetAllGroups = LocalStaticData.groups;
}
public List<GroupLocalEntity> GetAllGroup()
{
return GetAllGroups;
}
public GroupLocalEntity GetGroupById(int groupID)
{
return GetAllGroups.FirstOrDefault(g => g.Id == groupID);
}
public bool RemoveGroupById(int groupID)
{
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; // Успешное добавление
}
}
}