Exemplo n.º 1
0
        public async Task <bool> DeleteAll(List <TEntity> entities)
        {
            await using RecipeBookDbContext context = this._factory.CreateDbContext();
            context.Set <TEntity>().RemoveRange(entities);
            await context.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 2
0
        public async Task <TEntity> Update(TEntity entity)
        {
            await using RecipeBookDbContext context = this._factory.CreateDbContext();
            context.Set <TEntity>().Update(entity);
            await context.SaveChangesAsync();

            return(entity);
        }
Exemplo n.º 3
0
        public async Task <TEntity> Create(TEntity entity)
        {
            await using RecipeBookDbContext context = this._factory.CreateDbContext();
            var newEntry = await context.Set <TEntity>().AddAsync(entity);

            await context.SaveChangesAsync();

            return(newEntry.Entity);
        }
Exemplo n.º 4
0
        public async Task <List <TEntity> > FindBy(Func <TEntity, bool> predicate, Expression <Func <TEntity, object> >[] includes)
        {
            await using RecipeBookDbContext context = this._factory.CreateDbContext();

            IQueryable <TEntity> query = context.Set <TEntity>();

            query = includes.Aggregate(query, (current, expression) => current.Include(expression));

            return(query.Where(predicate).ToList());
        }
Exemplo n.º 5
0
 public async Task <List <TEntity> > FindBy(Func <TEntity, bool> predicate)
 {
     await using RecipeBookDbContext context = this._factory.CreateDbContext();
     return(context.Set <TEntity>().Where(predicate).ToList());
 }
Exemplo n.º 6
0
 public async Task <TEntity> FindOneBy(Expression <Func <TEntity, bool> > predicate)
 {
     await using RecipeBookDbContext context = this._factory.CreateDbContext();
     return(await context.Set <TEntity>().FirstOrDefaultAsync(predicate));
 }
Exemplo n.º 7
0
 public async Task <TEntity> Find(TId id)
 {
     await using RecipeBookDbContext context = this._factory.CreateDbContext();
     return(await context.Set <TEntity>().FindAsync(id));
 }
Exemplo n.º 8
0
 public async Task <List <TEntity> > GetAll()
 {
     await using RecipeBookDbContext context = this._factory.CreateDbContext();
     return(await context.Set <TEntity>().ToListAsync());
 }