public async Task <TEntityViewModel> GetAsync(int id, params Expression <Func <TEntity, object> >[] includeProperties) { var query = _db.Set <TEntity>().Where(x => x.Id == id); var mapped = query.ProjectTo <TEntityViewModel>(includeProperties); return(await mapped.FirstOrDefaultAsync()); }
public async Task <TEntity> DeleteAsync(int id) { var entity = await _db.Set <TEntity>().FirstOrDefaultAsync(x => x.Id == id); _db.Remove(entity); await _db.SaveChangesAsync(); return(entity); }
public async Task <TEntity> UpdateAsync(int id, TEntityBindingModel model) { var entity = await _db.Set <TEntity>().FirstOrDefaultAsync(x => x.Id == id); var dest = (TEntity)Mapper.Map(model, entity, typeof(TEntityBindingModel), typeof(TEntity)); _db.Update(dest); await _db.SaveChangesAsync(); return(dest); }
public async Task <IEnumerable <TEntityViewModel> > GetAsync( Expression <Func <TEntity, bool> > where, params Expression <Func <TEntity, object> >[] includeProperties) { var query = _db.Set <TEntity>().AsQueryable(); if (where != null) { query = query.Where(where); } var mapped = query.ProjectTo <TEntityViewModel>(includeProperties); return(await mapped.ToListAsync()); }