Exemplo n.º 1
0
        public ActionResult BillingAddress(AddressAndPaymentViewModel model)
        {
            try
            {
                var cart = ShoppingCart.GetShoppingCart(this.HttpContext);
                model.OrderDetails.CartCount = cart.GetCount();

                model.OrderDetails.Email     = User.Identity.Name;
                model.OrderDetails.OrderDate = DateTime.Now;
                model.OrderDetails.Status    = "In Progress";
                //Save Order
                db.Orders.Add(model.OrderDetails);
                db.SaveChanges();
                //Process the order
                cart.CreateOrder(model.OrderDetails);

                return(RedirectToAction("Complete",
                                        new { id = model.OrderDetails.OrderId, CartCount = 0 }));
            }
            catch
            {
                // Invalid - redisplay with errors
                return(View(model));
            }
        }
Exemplo n.º 2
0
        public ActionResult BillingAddress()
        {
            AddressAndPaymentViewModel model = new AddressAndPaymentViewModel();

            var cart  = ShoppingCart.GetShoppingCart(this.HttpContext);
            var email = User.Identity.Name;

            model.OrderDetails           = new Order();
            model.OrderDetails.CartCount = cart.GetCount();
            model.OrderDetails.Total     = cart.GetTotal();

            model.CartCount = cart.GetCount();
            model.CartId    = cart.GetCartId(this.HttpContext);

            return(View(model));
        }
Exemplo n.º 3
0
        public IActionResult AddressAndPayment(AddressAndPaymentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var order = new Order {
                    OrderDate  = DateTime.Now,
                    UserName   = User.Identity.Name,
                    FirstName  = model.FirstName,
                    LastName   = model.LastName,
                    Address    = model.Address,
                    City       = model.City,
                    State      = model.State,
                    PostalCode = model.PostalCode,
                    Country    = model.Country,
                    Phone      = model.Phone,
                    Email      = model.EmailAddress
                };

                if (string.Equals(model.PromoCode, PromoCode, StringComparison.OrdinalIgnoreCase) == false)
                {
                    return(View(model));
                }
                else
                {
                    try
                    {
                        _context.Orders.Add(order);
                        _context.SaveChanges();

                        var cart = ShoppingCart.GetCart(_context, this.HttpContext);
                        cart.CreateOrderDetails(order);

                        return(RedirectToAction("Complete", new { orderId = order.OrderId }));
                    }
                    catch (Exception ex)
                    {
                        //error!
                        return(View(model));
                    }
                }
            }

            return(View(model));
        }