presence/Demo/Data/Repository/GroupRepositoryImpl.cs

76 lines
1.9 KiB
C#
Raw Normal View History

2024-10-21 12:41:56 +00:00
using Demo.Data.Exceptions;
using Demo.Data.LocalData;
2024-10-25 08:47:11 +00:00
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.Data.Repository;
2024-10-21 12:41:56 +00:00
using Demo.domain.Models;
using System.Collections.Generic;
using System.Linq;
2024-10-25 08:47:11 +00:00
public class GroupRepositoryImpl: IGroupRepository
2024-10-21 12:41:56 +00:00
{
private List<GroupLocalEntity> _groups = LocalStaticData.groups;
public GroupLocalEntity? GetGroupById(int groupId)
{
foreach (var group in _groups)
{
if (group.Id == groupId)
{
return group;
}
}
return null;
}
// Метод для получения всех групп
public List<GroupLocalEntity> GetAllGroups() => _groups;
// Метод для добавления новой группы
public void AddGroup(GroupLocalEntity group)
{
group.Id = _groups.Any() ? _groups.Max(g => g.Id) + 1 : 1;
_groups.Add(group);
}
// Метод для обновления существующей группы
2024-10-25 09:41:35 +00:00
public void UpdateGroupById(int groupId, GroupLocalEntity updatedGroup)
2024-10-21 12:41:56 +00:00
{
2024-10-25 09:41:35 +00:00
var existingGroup = GetGroupById(groupId);
if (existingGroup == null) throw new GroupNotFoundException(groupId);
2024-10-21 12:41:56 +00:00
}
2024-10-25 09:41:35 +00:00
public void RemoveGroupById(int groupId)
2024-10-21 12:41:56 +00:00
{
2024-10-25 09:41:35 +00:00
var existingGroup = GetGroupById(groupId);
if (existingGroup == null) throw new GroupNotFoundException(groupId);
2024-10-21 12:41:56 +00:00
if (_groups.Contains(existingGroup))
{
_groups.Remove(existingGroup);
}
}
2024-10-25 08:47:11 +00:00
2024-10-25 09:41:35 +00:00
List<GroupDao> IGroupRepository.GetAllGroups()
2024-10-25 08:47:11 +00:00
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupDao updatedGroup)
{
throw new NotImplementedException();
}
2024-10-25 09:41:35 +00:00
GroupDao IGroupRepository.GetGroupById(int groupID)
2024-10-25 08:47:11 +00:00
{
throw new NotImplementedException();
}
2024-10-25 09:41:35 +00:00
public bool AddGroup(string Name)
2024-10-25 08:47:11 +00:00
{
throw new NotImplementedException();
}
2024-10-21 12:41:56 +00:00
}