Exemple #1
0
        public ActionResult SubmitOrder(CreditCardModel model)
        {
            if (ModelState.IsValid)
            {
                ViewBag.Header = "Order Confirmation";

                // data integration
                Order newOrder = new Order();
                ShoppingCartSaleModel _cartSale = cart.GetShoppingCart;
                newOrder.CustFK         = WebSecurity.CurrentUserId;
                newOrder.ShipDate       = DateTime.Now;
                newOrder.ExpArrivalDate = DateTime.Now;
                newOrder.ShipType       = _cartSale.ShipType;
                newOrder.PurchaseTotal  = _cartSale.SubTotal;
                newOrder.ShipCost       = _cartSale.ShippingCost;
                newOrder.OrderCost      = _cartSale.OrderTotal;

                foreach (ProductModel frontItem in _cartSale.ShoppingCartItems)
                {
                    OrderItem backItem = new OrderItem();
                    backItem.OrderFK   = newOrder.OrderID;
                    backItem.ProductFK = frontItem.ProductId;
                    backItem.Quantity  = frontItem.Quantity;
                    backItem.Cost      = frontItem.SalePrice;
                    newOrder.OrderItems.Add(backItem);
                }
                try
                {
                    this._uow.Orders.Add(newOrder);
                    this._uow.SaveChanges();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message.ToString());
                }

                cart.ResetCart();

                ViewBag.ItemCount = cart.ItemCount;
                return(View("ThankYou"));
            }
            else
            {
                ViewBag.ItemCount = cart.ItemCount;
                return(View("Payment", model));
            }
        }