예제 #1
0
        public ActionResult Finish(FormCollection form)
        {
            if (CartItems.Count <= 0)
            {
                return(RedirectToAction("Index", "Cart"));
            }
            var order  = new OrderSummary();
            var member = db.MemberShips.First(m => m.Email == User.Identity.Name);

            order.OrderDate = DateTime.Now;
            if (TryUpdateModel(order))
            {
                order.OrderDetails = GetOrderDetails(member);
                order.TotalTax     = CartItems.Sum(item => item.TaxPrice);
                order.Shipping     = member.Role == Role.Premium ? 0 : CartItems.Max(item => item.Shipping);
                order.TotalPrice   = Math.Round(CartItems.Sum(item => item.Price) + order.TotalTax + order.Shipping, 2);
                order.Member       = member;
                order.OrderStatus  = db.OrderStatuses.First(os => os.Id == 1);
                StockOut(order);
                db.Orders.Add(order);
                db.SaveChanges();
                CartItems.Clear();
                TempData["OrderId"] = order.Id;
                SendOrderMail(order);

                CheckAndUpgradeMember(order.Member);

                //Call Pay gateway
                return(RedirectToAction("InitiateCreditTransaction", new { transAmount = order.TotalPrice, orderId = order.Id }));
            }
            return(View("CheckOut"));
        }