namespace DataAccessLayer.Repository
{
public class GenericRepository<T> : IGenericDal<T> where T : class
{
public void Delete(T t)
{
using var c = new Context();
c.Remove(t);
c.SaveChanges();
}
public T GetById(int id)
{
using var c= new Context();
return c.Set<T>().Find(id);
}
public List<T> GetList()
{
using var c = new Context();
return c.Set<T>().ToList();
}
public List<T> GetListByFilter(Expression<Func<T, bool>> filter)
{
using var c = new Context();
return c.Set<T>().Where(filter).ToList();
}
public void Insert(T t)
{
using var c = new Context();
c.Add(t);
}
public void Update(T t)
{
using var c = new Context();
c.Update(t);
}
}
}