Raspisanie/Zurnal/RemaDateBase/Interfase/IGroupRepositoryes.cs

84 lines
2.2 KiB
C#
Raw Permalink Normal View History

2024-10-28 08:22:33 +00:00
using Zurnal.domain.Models;
2024-11-06 09:41:04 +00:00
using Zurnal.RemaDateBase.DateDao;
2024-10-24 11:43:25 +00:00
using Group = System.Text.RegularExpressions.Group;
2024-10-25 09:40:13 +00:00
namespace Zurnal.RemaDateBase
{
2024-10-28 08:22:33 +00:00
public interface IGroupRepository
2024-10-24 11:43:25 +00:00
{
2024-11-06 09:41:04 +00:00
List<GroupDao> AllGroup { get; }
public IEnumerable<GroupDao> AllGroups()
{
return AllGroup.Select(g => new GroupDao { GroupName = g.GroupName, Id = g.Id });
}
public bool RemoveGroupById(int groupId)
{
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
AllGroup.Remove(group);
return true;
}
return false;
}
public GroupDao FindGroupById(int groupId)
{
return AllGroup.FirstOrDefault(g => g.Id == groupId);
}
public bool UpdateGroupById(int groupId, GroupDao updatedGroup)
{
if (updatedGroup == null) throw new ArgumentNullException(nameof(updatedGroup));
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
group.GroupName = updatedGroup.GroupName;
return true;
}
return false;
}
public void DeleteGroup(int id)
{
var group = AllGroup.FirstOrDefault(g => g.Id == id);
if (group != null)
{
AllGroup.Remove(group);
}
}
public IEnumerable<GroupDao> GetAllGroups()
{
return AllGroup;
}
public void UpdateGroupName(int groupId, string name)
{
if (name == null) throw new ArgumentNullException(nameof(name));
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
group.GroupName = name;
}
}
public bool UpdateUser(Guid userGuid, UserDao updatedUser)
{
if (updatedUser == null) throw new ArgumentNullException(nameof(updatedUser));
var user = AllGroup.SelectMany(g => g.Users).FirstOrDefault(u => u.UserGuid == userGuid);
if (user != null)
{
user.FIO = updatedUser.FIO;
user.GroupID = updatedUser.GroupID;
user.Group = updatedUser.Group;
return true;
}
return false;
}
2024-10-24 11:43:25 +00:00
}
2024-10-25 09:40:13 +00:00
}