Raspisanie/Zurnal/Date/Repository/GroupRepositoryImpl.cs
2024-11-01 12:41:07 +03:00

119 lines
3.2 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.Name = name;
}
}
public GroupDao GetGroupById(int id)
{
return GroupDao.groups.FirstOrDefault(g => g.Id == id);
}
private static string GetDebuggerDisplay()
{
return $"GroupRepository with {GroupDao.groups.Count} groups";
}
public bool RemoveGroupById(int groupId)
{
var group = GroupDao.groups.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
GroupDao.groups.Remove(group);
return true;
}
return false;
}
public IEnumerable<GroupDao> AllGroups()
{
return GroupDao.groups.Select(g => new GroupDao { GroupName = g.Name, Id = g.Id });
}
public bool UpdateGroupById(int groupId, GroupDao updatedGroup)
{
var group = GroupDao.groups.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
group.Name = updatedGroup.GroupName;
return true;
}
return false;
}
public void UpdateGroup(GroupDao group)
{
var existingGroup = GroupDao.groups.FirstOrDefault(g => g.Id == group.Id);
if (existingGroup != null)
{
existingGroup.Name = group.GroupName;
}
}
public void DeleteGroup(int id)
{
var group = GroupDao.groups.FirstOrDefault(g => g.Id == id);
if (group != null)
{
GroupDao.groups.Remove(group);
}
}
public bool AddGroup(GroupDao newGroup)
{
if (newGroup == null)
{
throw new ArgumentNullException(nameof(newGroup));
}
GroupDao.groups.Add(newGroup);
return true;
}
public void AddGroupFromRegex(Group group)
{
throw new NotImplementedException();
}
IEnumerable<Group> IGroupRepository.AllGroups()
{
throw new NotImplementedException();
}
public void AddGroupFromRegex(Group group)
{
throw new NotImplementedException();
}
}
}