Demo/Data/Repository/GroupRepositoryImpl.cs
2024-10-21 13:55:18 +03:00

54 lines
1.7 KiB
C#

using Demo.Domain.Models;
using Demo.Data.LocalData;
namespace Demo.Data.Repository
{
public class GroupRepositoryImpl : IGroupRepository
{
public GroupRepositoryImpl() {
GetAllGroups = LocalStaticData.groups;
}
public List<GroupLocalEntity> GetAllGroups
{ get; set; }
public List<GroupLocalEntity> GetAllGroup()
{
return GetAllGroups;
}
public GroupLocalEntity? CreateGroup(GroupLocalEntity groupCreateLocalEntity) {
if (GetAllGroups.Any(x => x.ID == groupCreateLocalEntity.ID)) return null;
GetAllGroups.Add(groupCreateLocalEntity);
return groupCreateLocalEntity;
}
public GroupLocalEntity? UpdateGroup(GroupLocalEntity updatedGroup)
{
int index = GetAllGroups.FindIndex(x => x.ID == updatedGroup.ID);
if (index == -1) return null;
GetAllGroups[index].Name = updatedGroup.Name;
Console.WriteLine($"Обновленный Name: {GetAllGroups[index].Name}");
return GetAllGroups[index];
}
public bool RemoveGroupByID(int groupId)
{
GroupLocalEntity? groupLocal = GetAllGroups
.Where(x => x.ID == groupId).FirstOrDefault();
if (groupLocal == null) return false;
return GetAllGroups.Remove(groupLocal);
}
public GroupLocalEntity? GetGroupById(int groupId)
{
GroupLocalEntity? grouplocal = LocalStaticData.groups.Where(x => x.ID == groupId).FirstOrDefault();
if (grouplocal == null) return null;
return grouplocal;
}
}
}