49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using Demo.Data.RemoteData.RemoteDataBase;
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Demo.Data.Repository
|
|
{
|
|
public class SQLGroupRepositoryImpl : IGroupRepository
|
|
{
|
|
private readonly RemoteDatabaseContext _context;
|
|
|
|
public SQLGroupRepositoryImpl(RemoteDatabaseContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public IEnumerable<Group> GetAllGroups()
|
|
{
|
|
return _context.Groups.ToList();
|
|
}
|
|
|
|
public void AddGroup(Group group)
|
|
{
|
|
_context.Groups.Add(group);
|
|
_context.SaveChanges();
|
|
}
|
|
|
|
public void UpdateGroupName(int id, string name)
|
|
{
|
|
var group = _context.Groups.Find(id);
|
|
if (group != null)
|
|
{
|
|
group.Name = name;
|
|
_context.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public void DeleteGroup(int id)
|
|
{
|
|
var group = _context.Groups.Find(id);
|
|
if (group != null)
|
|
{
|
|
_context.Groups.Remove(group);
|
|
_context.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
} |