Files
constructdemo/ConstructorApp.DataAccessLayer/Repositories/GenericRepository.cs
2025-05-01 15:18:30 +03:00

50 lines
1.1 KiB
C#

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