2024-10-17 11:46:19 +00:00
|
|
|
using Demo.Domain.Models;
|
|
|
|
using Demo.Data.LocalData;
|
|
|
|
|
|
|
|
namespace Demo.Data.Repository
|
|
|
|
{
|
2024-10-21 09:38:07 +00:00
|
|
|
public class GroupRepositoryImpl : IGroupRepository
|
2024-10-17 11:46:19 +00:00
|
|
|
{
|
|
|
|
public GroupRepositoryImpl() {
|
|
|
|
|
|
|
|
GetAllGroups = LocalStaticData.groups;
|
|
|
|
}
|
|
|
|
public List<GroupLocalEntity> GetAllGroups
|
|
|
|
{ get; set; }
|
|
|
|
|
2024-10-21 09:38:07 +00:00
|
|
|
public List<GroupLocalEntity> GetAllGroup()
|
2024-10-17 11:46:19 +00:00
|
|
|
{
|
2024-10-21 09:38:07 +00:00
|
|
|
return GetAllGroups;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GroupLocalEntity? CreateGroup(GroupLocalEntity groupCreateLocalEntity) {
|
|
|
|
|
|
|
|
if (GetAllGroups.Any(x => x.ID == groupCreateLocalEntity.ID)) return null;
|
|
|
|
|
|
|
|
GetAllGroups.Add(groupCreateLocalEntity);
|
|
|
|
return groupCreateLocalEntity;
|
2024-10-17 11:46:19 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 09:38:07 +00:00
|
|
|
public GroupLocalEntity? UpdateGroup(GroupLocalEntity updatedGroup)
|
2024-10-17 11:46:19 +00:00
|
|
|
{
|
2024-10-21 09:38:07 +00:00
|
|
|
int index = GetAllGroups.FindIndex(x => x.ID == updatedGroup.ID);
|
2024-10-17 11:46:19 +00:00
|
|
|
if (index == -1) return null;
|
2024-10-21 09:38:07 +00:00
|
|
|
GetAllGroups[index].Name = updatedGroup.Name;
|
2024-10-17 11:46:19 +00:00
|
|
|
Console.WriteLine($"Обновленный Name: {GetAllGroups[index].Name}");
|
|
|
|
return GetAllGroups[index];
|
|
|
|
}
|
2024-10-21 09:38:07 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2024-10-17 11:46:19 +00:00
|
|
|
}
|
|
|
|
}
|