public object Order(string username, int dishId) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Order order = new Order { Date= DateTime.Now, State = 0, UserName=username, DishId=dishId }; db.Order.Add(order); int result = db.SaveChanges(); if(result > 0) { return new { Response = true }; } return new { Response = false }; }
public IHttpActionResult EditOrder(int id, Order order) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != order.Id) { return BadRequest(); } db.Entry(order).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }