slarny4/Demo1/Data/Repository/SQLGroupRepositoryImpl.cs

49 lines
1.2 KiB
C#
Raw Normal View History

2024-12-02 10:24:02 +00:00
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
2024-11-25 04:33:26 +00:00
using Microsoft.EntityFrameworkCore;
2024-10-28 12:42:04 +00:00
using System.Collections.Generic;
using System.Linq;
2024-11-25 04:33:26 +00:00
namespace Demo.Data.Repository
2024-10-28 12:42:04 +00:00
{
2024-11-25 04:33:26 +00:00
public class SQLGroupRepositoryImpl : IGroupRepository
2024-10-28 12:42:04 +00:00
{
2024-12-02 10:24:02 +00:00
private readonly RemoteDatabaseContext _context;
2024-11-25 04:33:26 +00:00
2024-12-02 10:24:02 +00:00
public SQLGroupRepositoryImpl(RemoteDatabaseContext context)
2024-11-25 04:33:26 +00:00
{
_context = context;
}
public IEnumerable<Group> GetAllGroups()
{
2024-12-02 10:24:02 +00:00
return _context.Groups.ToList();
2024-11-25 04:33:26 +00:00
}
public void AddGroup(Group group)
{
2024-12-02 10:24:02 +00:00
_context.Groups.Add(group);
2024-11-25 04:33:26 +00:00
_context.SaveChanges();
}
public void UpdateGroupName(int id, string name)
{
2024-12-02 10:24:02 +00:00
var group = _context.Groups.Find(id);
2024-11-25 04:33:26 +00:00
if (group != null)
{
group.Name = name;
_context.SaveChanges();
}
}
public void DeleteGroup(int id)
{
2024-12-02 10:24:02 +00:00
var group = _context.Groups.Find(id);
2024-11-25 04:33:26 +00:00
if (group != null)
{
2024-12-02 10:24:02 +00:00
_context.Groups.Remove(group);
2024-11-25 04:33:26 +00:00
_context.SaveChanges();
}
}
2024-10-28 12:42:04 +00:00
}
2024-11-25 04:33:26 +00:00
}