slarny4/Demo1/Data/Repository/GroupRepositoryImpl.cs

52 lines
1.5 KiB
C#
Raw Permalink Normal View History

2024-10-28 12:42:04 +00:00
// C:\Users\adm\Source\Repos\presence1\Demo\Data\Repository\GroupRepositoryImpl.cs
using System.Collections.Generic;
using System.Linq;
using Demo.Data.Exceptions;
using Demo.Data.LocalData;
using Demo.Data.LocalData.Entity;
using Demo.Data.RemoteData.RemoteDataBase;
namespace Demo.Data.Repository
2024-10-21 22:57:01 +00:00
{
2024-10-24 08:50:32 +00:00
public class GroupRepositoryImpl : IGroupRepository
2024-10-21 22:57:01 +00:00
{
2024-10-28 12:42:04 +00:00
private RemoteDatabaseContext context;
2024-10-21 22:57:01 +00:00
2024-10-28 12:42:04 +00:00
public GroupRepositoryImpl(RemoteDatabaseContext context)
2024-10-21 22:57:01 +00:00
{
2024-10-28 12:42:04 +00:00
this.context = context;
2024-10-21 22:57:01 +00:00
}
2024-10-28 12:42:04 +00:00
public void AddGroup(Group group)
2024-10-21 22:57:01 +00:00
{
2024-10-28 12:42:04 +00:00
if (LocalStaticData.Groups.Any(g => g.Id == group.Id))
throw new RepositoryException("Group with the same ID already exists.");
LocalStaticData.Groups.Add(group);
2024-10-24 08:50:32 +00:00
}
2024-10-28 12:42:04 +00:00
public void DeleteGroup(int id)
2024-10-24 08:50:32 +00:00
{
2024-10-28 12:42:04 +00:00
var group = GetGroupById(id);
LocalStaticData.Groups.Remove(group);
2024-10-21 22:57:01 +00:00
}
2024-10-28 12:42:04 +00:00
public IEnumerable<Group> GetAllGroups()
2024-10-21 22:57:01 +00:00
{
2024-10-28 12:42:04 +00:00
return LocalStaticData.Groups;
2024-10-21 22:57:01 +00:00
}
2024-10-23 09:52:43 +00:00
2024-10-28 12:42:04 +00:00
public Group GetGroupById(int id)
2024-10-23 09:52:43 +00:00
{
2024-10-28 12:42:04 +00:00
var group = LocalStaticData.Groups.FirstOrDefault(g => g.Id == id);
2024-10-24 08:50:32 +00:00
if (group == null)
2024-10-28 12:42:04 +00:00
throw new GroupNotFoundException(id);
return group;
}
2024-10-24 08:50:32 +00:00
2024-10-28 12:42:04 +00:00
public void UpdateGroup(Group group)
{
var existingGroup = GetGroupById(group.Id);
existingGroup.Name = group.Name;
2024-10-23 09:52:43 +00:00
}
2024-10-21 22:57:01 +00:00
}
2024-10-24 08:50:32 +00:00
}