80 lines
2.0 KiB
C#
80 lines
2.0 KiB
C#
using System.Diagnostics;
|
|
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);
|
|
}
|
|
}
|
|
public GroupDao FindGroupById(int groupId)
|
|
{
|
|
return AllGroup.FirstOrDefault(g => g.Id == groupId);
|
|
}
|
|
}
|
|
} |