public virtual async Task PostAsync(TModel contract) { var mapped = this.mapper.Map <TEntity>(contract); context.Set <TEntity>().Add(mapped); await context.SaveChangesAsync(); }
public async Task <IActionResult> PutProduct([FromRoute] int id, [FromBody] Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.ProductId) { return(BadRequest()); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { _logger.LogError(ex.ToString()); if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public async Task <IActionResult> PutProduct(int id, Product product) { _logger.Information("Saving Product with id={id}", id); if (id != product.ProductId) { _logger.Warning("The product with id={id} does not match to product with id={productId}", id, product.ProductId); return(BadRequest()); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { _logger.Warning("The product with id={id} is not found", id); return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task SaveAsync() { await _adventureWorks2016ContextContext.SaveChangesAsync(); }