Example #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);
        }
Example #2
0
        public IHttpActionResult PostOrder(Order order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            return CreatedAtRoute("DefaultApi", new { id = order.Id }, order);
        }
Example #3
0
        public ActionResult Finish()
        {
            ShoppingCartViewModel cart = GetCart();
            if (ModelState.IsValid)
            {

                Order order = new Order { OrderStatusId = int.Parse(ConfigurationManager.AppSettings["DefaultOrderStatusId"]) };

                cart.Items.ForEach(cartItem => {
                    order.Items.Add(
                        new OrderItem {
                        ProductId = cartItem.Product.Id,
                        Quantity = cartItem.Ammount,
                        Price = cartItem.Ammount * cartItem.Product.Price } );
                });
                db.Orders.Add(order);
                db.SaveChanges();

                CleanCart();
                return RedirectToAction("Finish");
            }

            return View("Index", cart);
        }