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 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();
            }
        }
    }
}