public async Task <T> Update(Guid id, T entity) { using (FoodFightDbContext context = _dBContextFactory.CreateDbContext()) { entity.Id = id; context.Set <T>().Update(entity); await context.SaveChangesAsync(); return(entity); } }
public async Task <T> Create(T entity) { using (FoodFightDbContext context = _dBContextFactory.CreateDbContext()) { EntityEntry <T> createdResult = await context.Set <T>().AddAsync(entity); await context.SaveChangesAsync(); return(createdResult.Entity); } }
public async Task <bool> Delete(Guid id) { using (FoodFightDbContext context = _dBContextFactory.CreateDbContext()) { T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.Id == id); context.Set <T>().Remove(entity); await context.SaveChangesAsync(); return(true); } }