Exemplo n.º 1
0
        public ActionResult Checkout(ShopCartItemServiceClient cart, CustomerAddressService.ShoppingDetailsDTO shoppingDetails)
        {
            Factory factory = new Factory();

            if (cart.Lines().Count() == 0)
            {
                ModelState.AddModelError("", "Sorry, your cart is empty!");
            }
            if (addressService.GetStateProvince(shoppingDetails.City, shoppingDetails.Country) < 1)
            {
                ModelState.AddModelError("", "Incorrect City in country");
            }
            var cartLine = factory.CreateCartLine(cart.Lines());
            var details  = factory.CreateShoppingDetails(shoppingDetails);

            if (ModelState.IsValid)
            {
                int userID = HttpContext.GetOwinContext()
                             .GetUserManager <ApplicationUserManager>()
                             .FindById(Convert.ToInt32(User.Identity.GetUserId())).BusinessEntityID;
                string email = HttpContext.GetOwinContext()
                               .GetUserManager <ApplicationUserManager>()
                               .FindById(Convert.ToInt32(User.Identity.GetUserId())).Email;

                orderService.ProcessOrder(cartLine.ToArray(), details, userID, email);

                cart.Clear();
                return(View("Completed"));
            }
            else
            {
                ViewBag.Country = Countries;
                return(View(shoppingDetails));
            }
        }
Exemplo n.º 2
0
 public OrderProcessorService.ShoppingDetailsDTO CreateShoppingDetails(CustomerAddressService.ShoppingDetailsDTO shoppingDetails)
 {
     OrderProcessorService.ShoppingDetailsDTO result = new OrderProcessorService.ShoppingDetailsDTO()
     {
         Address    = shoppingDetails.Address,
         City       = shoppingDetails.City,
         PostalCode = shoppingDetails.PostalCode,
         Country    = shoppingDetails.Country
     };
     return(result);
 }