Raspisanie/Zurnal/Date/Repository/GroupRepositoryImpl.cs

119 lines
3.2 KiB
C#
Raw Normal View History

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