Add project files.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using ConstructorApp.DataAccessLayer.Abstract;
|
||||
using ConstructorApp.DataAccessLayer.Concrete;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ConstructorApp.DataAccessLayer.Repositories
|
||||
{
|
||||
public class GenericRepository<T> : IGenericDal<T> where T : class
|
||||
{
|
||||
private readonly ConstructorContext _context;
|
||||
|
||||
public GenericRepository(ConstructorContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public void Add(T entity)
|
||||
{
|
||||
_context.Add(entity);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void Delete(T entity)
|
||||
{
|
||||
_context.Remove(entity);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public T GetByID(int id)
|
||||
{
|
||||
return _context.Set<T>().Find(id);
|
||||
}
|
||||
|
||||
public List<T> GetListAll()
|
||||
{
|
||||
return _context.Set<T>().ToList();
|
||||
}
|
||||
|
||||
public async Task<List<T>> GetListAllAsync()
|
||||
{
|
||||
return await _context.Set<T>().ToListAsync();
|
||||
}
|
||||
|
||||
public void Update(T entity)
|
||||
{
|
||||
_context.Update(entity);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user