Ejemplo n.º 1
0
        //
        // GET: /PizzaBasket/

        public ActionResult Index()
        {
            ShoppingBasketHelper helper = new ShoppingBasketHelper();

            //  Set  up  our  ViewModel
            var viewModel = new ShoppingBasketViewModel
            {
                BasketItems = helper.GetCartItems(),
                BasketTotal = helper.GetTotal()
            };

            //  Return  the  view
            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult  RemoveFromCart(int id)
        {
            ShoppingBasketHelper helper = new ShoppingBasketHelper();

//  Get  the  name  of  the  album  to  display  confirmation

            string itemName = db.Items
                              .Single(item => item.ItemId == id).ItemName;

//  Remove  from  cart
            int itemCount = helper.RemoveFromBasket(id);

//  Display  the  confirmation  message
            var results = new  ShoppingBasketRemoveViewModel
            {
                Message     = Server.HtmlEncode(itemName) + "  has  been  removed  from  your  shopping  cart.",
                BasketTotal = helper.GetTotal(),
                BasketCount = helper.GetBasketCount(),
                DeleteId    = id
            };

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public ActionResult Index(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);
            try
            {
                ShoppingBasketHelper helper = new ShoppingBasketHelper();
                decimal priceAfterDiscount  = helper.getDiscountedPrice(values["PromoCode"], helper.GetTotal());

                order.OrderDate   = DateTime.Now;
                order.OrderStatus = "Undelivered";
                order.Total       = priceAfterDiscount;
                db.Orders.Add(order);

                List <BasketItem> currentItem = helper.GetCartItems();
                foreach (BasketItem element in currentItem.ToList())
                {
                    var orderDetail = new OrderDetail
                    {
                        ItemId    = element.ItemId,
                        OrderId   = order.OrderId,
                        UnitPrice = element.Item.ItemPrice,
                        Quantity  = element.Count
                    };
                    db.OrderDetails.Add(orderDetail);
                }

                db.SaveChanges();
                return(RedirectToAction("Complete", new { orderId = order.OrderId, orderTotal = order.Total }));
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
                return(View(order));
            }
        }