public async Task <IActionResult> PutOrder([FromRoute] int id, [FromBody] Order order) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != order.OrderID) { return(BadRequest()); } _context.Entry(order).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Post(string values) { var model = new Order(); var valuesDict = JsonConvert.DeserializeObject <IDictionary>(values); PopulateModel(model, valuesDict); if (!TryValidateModel(model)) { return(BadRequest(GetFullErrorMessage(ModelState))); } var result = _context.Order.Add(model); await _context.SaveChangesAsync(); return(Json(result.Entity.OrderID)); }