slarny4/Demo1/Data/Repository/GroupRepositoryImpl.cs
atabidze105 ad36f40a57 init
2024-10-24 11:50:32 +03:00

60 lines
1.7 KiB
C#
Raw 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 AttendanceApp.Data.Exceptions;
using AttendanceApp.Data.LocalData;
using AttendanceApp.Domain.Models;
namespace AttendanceApp.Data.Repository
{
public class GroupRepositoryImpl : IGroupRepository
{
private readonly List<LocalGroup> _groups = LocalStaticData.Groups;
public IEnumerable<Group> GetAllGroups()
{
return _groups.Select(g => new Group
{
Id = g.Id,
Name = g.Name
});
}
public Group GetGroupById(int id)
{
var localGroup = _groups.FirstOrDefault(g => g.Id == id);
if (localGroup == null)
throw new GroupNotFoundException($"Группа с ID {id} не найдена.");
return new Group
{
Id = localGroup.Id,
Name = localGroup.Name
};
}
public void AddGroup(Group group)
{
_groups.Add(new LocalGroup
{
Id = group.Id,
Name = group.Name
});
}
public void UpdateGroup(Group group)
{
var localGroup = _groups.FirstOrDefault(g => g.Id == group.Id);
if (localGroup == null)
throw new GroupNotFoundException($"Группа с ID {group.Id} не найдена.");
localGroup.Name = group.Name;
}
public void DeleteGroup(int id)
{
var group = _groups.FirstOrDefault(g => g.Id == id);
if (group == null)
throw new GroupNotFoundException($"Группа с ID {id} не найдена.");
_groups.Remove(group);
}
}
}