public IHttpActionResult PostOrderItemByTableId(int tableid, OrderItem item) { var order = db.Orders.Single(o => o.TableId == tableid); var _item = new OrderItem { OrderId = order.Id, ProductId = item.ProductId, Quantity = item.Quantity }; return PostOrderItem(_item); }
public IHttpActionResult PostOrderItem(OrderItem orderItem) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.OrderItems.Add(orderItem); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = orderItem.Id }, orderItem); }
public IHttpActionResult PutOrderItem(int id, OrderItem orderItem) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != orderItem.Id) { return BadRequest(); } db.Entry(orderItem).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OrderItemExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }