Ejemplo 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));
            }
        }
Ejemplo n.º 2
0
        public ActionResult List(ShopCartItemServiceClient cart, string category, string subcategory, int page = 1, string name = null)
        {
            ProductsListView productsList = new ProductsListView
            {
                CurrentCategory = category,
                SubCategory     = subcategory,
                ProductName     = name,
                PagingInfo      = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = name == null?dataRepository.GetList().Where(x => x.SubCategory == subcategory).Count()
                                       : dataRepository.GetList().Where(x => x.Name.Contains(name)).Count()
                },
                ProductCatalog = subcategory != null?dataRepository.GetList()
                                 .Where(x => x.SubCategory == subcategory || x.SubCategory == null)
                                 .OrderBy(x => x.ID)
                                 .Skip((page - 1) * PageSize)
                                 .Take(PageSize) : dataRepository.GetList().Where(x => x.Name.Contains(name))
                                     .OrderBy(x => x.ID).Skip((page - 1) * PageSize).Take(PageSize),
                                     Cart = cart
            };

            productsList.CountActualProduct();
            return(View(productsList));
        }
Ejemplo n.º 3
0
 public ActionResult Index(ShopCartItemServiceClient cart, string returnUrl)
 {
     return(View(new ShopCartItemViewModel
     {
         ReturnUrl = returnUrl,
         Cart = cart
     }));
 }
Ejemplo n.º 4
0
        public RedirectToRouteResult RemoveFromCart(ShopCartItemServiceClient cart, int productId, string returnUrl)
        {
            Factory factory = new Factory();

            ProductService.ProductDTO product = productService.GetProduct(productId);
            var productDTO = factory.CreateProductDTO(product);


            if (productDTO != null)
            {
                cart.RemoveLine(productDTO);
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
Ejemplo n.º 5
0
        public object BindModel(ControllerContext controllerContext,
                                ModelBindingContext bindingContext)
        {
            ShopCartItemServiceClient cart = null;

            if (controllerContext.HttpContext.Session != null)
            {
                cart = (ShopCartItemServiceClient)controllerContext.HttpContext.Session[sessionKey];
            }
            if (cart == null)
            {
                cart = new ShopCartItemServiceClient();
                if (controllerContext.HttpContext.Session != null)
                {
                    controllerContext.HttpContext.Session[sessionKey] = cart;
                }
            }
            return(cart);
        }
Ejemplo n.º 6
0
 public PartialViewResult Summary(ShopCartItemServiceClient check)
 {
     return(PartialView(check));
 }