Spaces:
Sleeping
Sleeping
Download ECommerce.Model/Repositories/Repository.cs from Danishathugging/danstore: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/Danishathugging/danstore/resolve/main/ECommerce.Model/Repositories/Repository.cs
- Command line
-
hf download hf://spaces/Danishathugging/danstore/ECommerce.Model/Repositories/Repository.cs
-
curl -L -o Repository.cs https://huggingface.co/spaces/Danishathugging/danstore/resolve/main/ECommerce.Model/Repositories/Repository.cs
1.07 kB
| using System.Linq.Expressions; | |
| using ECommerce.Model.Data; | |
| using Microsoft.EntityFrameworkCore; | |
| namespace ECommerce.Model.Repositories; | |
| public class Repository<T> : IRepository<T> where T : class | |
| { | |
| protected readonly AppDbContext _context; | |
| protected readonly DbSet<T> _dbSet; | |
| public Repository(AppDbContext context) { _context = context; _dbSet = context.Set<T>(); } | |
| public virtual async Task<T?> GetByIdAsync(Guid id) => await _dbSet.FindAsync(id); | |
| public virtual async Task<IReadOnlyList<T>> GetAllAsync() => await _dbSet.ToListAsync(); | |
| public virtual async Task<IReadOnlyList<T>> FindAsync(Expression<Func<T, bool>> predicate) => await _dbSet.Where(predicate).ToListAsync(); | |
| public virtual async Task<T> AddAsync(T entity) { await _dbSet.AddAsync(entity); await _context.SaveChangesAsync(); return entity; } | |
| public virtual async Task UpdateAsync(T entity) { _dbSet.Update(entity); await _context.SaveChangesAsync(); } | |
| public virtual async Task DeleteAsync(T entity) { _dbSet.Remove(entity); await _context.SaveChangesAsync(); } | |
| } | |