2024-11-01 07:49:39 +00:00
|
|
|
|
using Zurnal.RemaDateBase.DateDao;
|
2024-10-31 11:37:45 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-11-01 06:57:09 +00:00
|
|
|
|
using Group = System.Text.RegularExpressions.Group;
|
2024-10-21 11:56:16 +00:00
|
|
|
|
|
|
|
|
|
namespace Zurnal.Date.Repository
|
|
|
|
|
{
|
|
|
|
|
internal interface IGroupRepository
|
2024-11-01 07:49:39 +00:00
|
|
|
|
{
|
|
|
|
|
List<GroupDao> AllGroup { get; }
|
|
|
|
|
|
2024-11-02 10:40:07 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-01 07:49:39 +00:00
|
|
|
|
void AddGroupFromRegex(Group group);
|
2024-11-02 10:40:07 +00:00
|
|
|
|
public GroupDao GetGroupById(int id);
|
2024-11-01 07:49:39 +00:00
|
|
|
|
IEnumerable<GroupDao> GetAllGroups();
|
2024-11-02 10:40:07 +00:00
|
|
|
|
public void UpdateGroupName(int groupId, string name)
|
|
|
|
|
{
|
|
|
|
|
var group = GroupDao.Name.FirstOrDefault(g => g.Id == groupId);
|
|
|
|
|
if (group != null)
|
|
|
|
|
{
|
|
|
|
|
group.GroupName = name;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-01 07:49:39 +00:00
|
|
|
|
}
|
2024-10-31 11:37:45 +00:00
|
|
|
|
|
|
|
|
|
internal class ServiceConfiguration
|
|
|
|
|
{
|
|
|
|
|
public static void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddDbContext<RemoteDateBaseContext>()
|
2024-11-02 10:40:07 +00:00
|
|
|
|
.AddScoped<IGroupRepository>();
|
2024-10-31 11:37:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|