Beispiel #1
0
        public int CreateOrder(Order order)
        {
            decimal orderTotal = 0;

            var cartItems = GetCartItems();

            foreach (var item in cartItems)
            {
                var orderDetail = new OrderDetail
                {
                    AlbumId = item.AlbumId,
                    OrderId = order.OrderId,
                    UnitPrice = item.Album.Price,
                    Quatity = item.Count
                };

                orderTotal = (item.Count * item.Album.Price);

                storeDB.OrderDetails.Add(orderDetail);
            }

            order.Total = orderTotal;

            storeDB.SaveChanges();

            EmptyCart();

            return order.OrderId;
        }
Beispiel #2
0
 public ActionResult Edit(Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "Username", order.CustomerID);
     return View(order);
 }
Beispiel #3
0
        public ActionResult Create(Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(order);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "Username", order.CustomerID);
            return View(order);
        }
Beispiel #4
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();
            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode,
                    StringComparison.OrdinalIgnoreCase) == false)
                {
                    return View(order);
                }
                else
                {
                    order.Username = User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    //Save Order
                    storeDB.Orders.Add(order);
                    storeDB.SaveChanges();

                    //Process the order
                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.CreateOrder(order);

                    return RedirectToAction("Complete",
                        new { id = order.OrderId });
                }

            }
            catch
            {
                //Invalid - redisplay with errors
                return View(order);
            }
        }
Beispiel #5
0
 public int CreateOrder(Order order)
 {
     decimal orderTotal = 0;
     var cartItems = GetCartItems();
     // Iterate over the items in the cart, adding the order details for each
     foreach (var item in cartItems)
     {
         var orderDetail = new OrderDetail
         {
             AlbumId = item.AlbumId,
             OrderId = order.OrderId,
             UnitPrice = item.Album.Price,
             Quantity = item.Count
         };
         // Set the order total of the shopping cart
         orderTotal += (item.Count * item.Album.Price);
         storeDB.OrderDetails.Add(orderDetail);
     }
     // Set the order's total to the orderTotal count
     order.Total = orderTotal;
     // Save the order
     storeDB.SaveChanges();
     // Empty the shopping cart
     EmptyCart();
     // Return the OrderId as the confirmation number
     return order.OrderId;
 }