Raspisanie/Zurnal/Date/Repository/GroupRepositoryImpl.cs
2024-11-02 10:50:36 +03:00

105 lines
2.6 KiB
C#

using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;
using Zurnal.Date.LocalDate;
using Zurnal.Date.Repository;
using Zurnal.RemaDateBase.DateDao;
using System.Text.RegularExpressions;
namespace Zurnal.Data.Repository
{
[DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")]
public class GroupRepositoryImpl : IGroupRepository
{
public List<GroupDao> AllGroup => GroupDao.Name.ToList();
public IEnumerable<GroupDao> GetAllGroups()
{
return GroupDao.Name;
}
public void AddGroup(GroupDao group)
{
if (group == null)
{
throw new ArgumentNullException(nameof(group));
}
GroupDao.Name.Add(group);
}
public void UpdateGroupName(int groupId, string name)
{
var group = GroupDao.Name.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
group.GroupName = name;
}
}
public bool UpdateGroupById(int groupId, GroupDao updatedGroup)
{
var group = GroupDao.Name.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
group.GroupName = updatedGroup.GroupName;
return true;
}
return false;
}
private static string GetDebuggerDisplay()
{
return $"GroupRepository with {GroupDao.Name.Count} groups";
}
public bool RemoveGroupById(int groupId)
{
var group = GroupDao.Name.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
GroupDao.Name.Remove(group);
return true;
}
return false;
}
public IEnumerable<GroupDao> AllGroups()
{
return GroupDao.Name.Select(g => new GroupDao { GroupName = g.GroupName, Id = g.Id });
}
public void DeleteGroup(int id)
{
var group = GroupDao.Name.FirstOrDefault(g => g.Id == id);
if (group != null)
{
GroupDao.Name.Remove(group);
}
}
IEnumerable<Group> IGroupRepository.AllGroups()
{
throw new NotImplementedException();
}
bool IGroupRepository.AddGroup(GroupDao newGroup)
{
throw new NotImplementedException();
}
public void AddGroupFromRegex(Group group)
{
throw new NotImplementedException();
}
public GroupDao GetGroupById(int id)
{
throw new NotImplementedException();
}
public void UpdateGroup(GroupDao group)
{
throw new NotImplementedException();
}
}
}