Raspisanie/Zurnal/Date/Repository/IGroupRepository.cs
2024-11-02 13:40:07 +03:00

65 lines
1.8 KiB
C#

using Zurnal.RemaDateBase.DateDao;
using Microsoft.Extensions.DependencyInjection;
using Group = System.Text.RegularExpressions.Group;
namespace Zurnal.Date.Repository
{
internal interface IGroupRepository
{
List<GroupDao> AllGroup { get; }
public IEnumerable<GroupDao> AllGroups()
{
return GroupDao.Name.Select(g => new GroupDao { GroupName = g.GroupName, Id = g.Id });
}
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 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;
}
public void DeleteGroup(int id)
{
var group = GroupDao.Name.FirstOrDefault(g => g.Id == id);
if (group != null)
{
GroupDao.Name.Remove(group);
}
}
void AddGroupFromRegex(Group group);
public GroupDao GetGroupById(int id);
IEnumerable<GroupDao> GetAllGroups();
public void UpdateGroupName(int groupId, string name)
{
var group = GroupDao.Name.FirstOrDefault(g => g.Id == groupId);
if (group != null)
{
group.GroupName = name;
}
}
}
internal class ServiceConfiguration
{
public static void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<RemoteDateBaseContext>()
.AddScoped<IGroupRepository>();
}
}
}