2024-11-25 04:33:26 +00:00
|
|
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
|
|
|
|
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-11-25 04:33:26 +00:00
|
|
|
|
private readonly DbContext _context;
|
|
|
|
|
|
|
|
|
|
public SQLGroupRepositoryImpl(DbContext context)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Group> GetAllGroups()
|
|
|
|
|
{
|
|
|
|
|
return _context.Set<Group>().ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddGroup(Group group)
|
|
|
|
|
{
|
|
|
|
|
_context.Set<Group>().Add(group);
|
|
|
|
|
_context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateGroupName(int id, string name)
|
|
|
|
|
{
|
|
|
|
|
var group = _context.Set<Group>().Find(id);
|
|
|
|
|
if (group != null)
|
|
|
|
|
{
|
|
|
|
|
group.Name = name;
|
|
|
|
|
_context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteGroup(int id)
|
|
|
|
|
{
|
|
|
|
|
var group = _context.Set<Group>().Find(id);
|
|
|
|
|
if (group != null)
|
|
|
|
|
{
|
|
|
|
|
_context.Set<Group>().Remove(group);
|
|
|
|
|
_context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-28 12:42:04 +00:00
|
|
|
|
}
|
2024-11-25 04:33:26 +00:00
|
|
|
|
}
|