public ActionResult Checkout(Payment Payment)
        {
            if (new CartBusiness { UserKey = Session.GetUserKey() }.GetCurrentCartCount() <= 0)
            {
                var ex = new HttpException(400, "");
                ex.Data["ErrType"] = Globals.ERRTYPES.CART_CARTEMPTY;
                throw ex;
            }
            var orderBusiness = new OrderBusiness();
            var currentOrder = orderBusiness.GetIncompleteOrder(Session.GetUserKey());
            if (currentOrder == null)
            {
                var ex = new HttpException(404, "");
                ex.Data["ErrType"] = Globals.ERRTYPES.ORDER_NOTFOUND;
                throw ex;
            }

            decimal ItemsTotal;
            decimal ShippingPrice;
            decimal OrderTotal;
            orderBusiness.CalculateOrderSummary(out ItemsTotal, out ShippingPrice, out OrderTotal, currentOrder);
            if (OrderTotal != Payment.AmountPaid)
            {
                var ex = new HttpException(400, "");
                ex.Data["ErrType"] = Globals.ERRTYPES.CHECKOUT_PAYMENTERROR;
                throw ex;
            }

            orderBusiness.Checkout(Payment, currentOrder);

            // order completed, SEND E-MAIL

            return RedirectToAction("CheckoutComplete", currentOrder);
        }
Esempio n. 2
0
        /// <summary>
        /// Makes the payment, and if successful, completes the order.
        /// </summary>
        /// <param name="Payment"></param>
        /// <param name="Order"></param>
        internal void Checkout(Payment Payment, Order Order)
        {
            Order.MoneyTransfers.Add(Payment);

            Order.Status = Globals.ORDERSTATUS_COMPLETE;
            Order.Statuses.Add(new OrderStatus { State = Globals.ORDERSTATUS_COMPLETE, Date = DateTime.Now });
            Order.Carts.ToList().AsParallel().ForAll(c => c.OrderCompleted = true);
            SaveChanges();
        }