コード例 #1
0
        public IHttpActionResult PutOrder(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);
        }
コード例 #2
0
        public IHttpActionResult PostOrder(OrderViewModel order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            Order neworder = new Order();
            var menuItem = db.MenuItems.Find(order.ItemId);

            neworder.Item = menuItem;
            neworder.Username = order.User;
            neworder.CreatedOn = DateTime.UtcNow;

            db.Orders.Add(neworder);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = order }, order);
        }