60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
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);
|
||
}
|
||
}
|
||
} |