public IActionResult Index()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            ShoppingCartVm = new ShoppingCartVm()
            {
                OrderHeader = new Models.OrderHeader(),
                ListCart    = _unitofWork.ShoppingCart.GetAll(u => u.ApplicationUserId == claim.Value, includeProperties: "Product")
            };
            ShoppingCartVm.OrderHeader.OrderTotal      = 0;
            ShoppingCartVm.OrderHeader.ApplicationUser = _unitofWork.ApplicationUser
                                                         .GetFirstOrDefault(u => u.Id == claim.Value, includeProperties: "Company");

            foreach (var list in ShoppingCartVm.ListCart)
            {
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.Product.Price,
                                                        list.Product.Price50, list.Product.Price100);
                ShoppingCartVm.OrderHeader.OrderTotal += (list.Price * list.Count);
                list.Product.Description = SD.ConvertToRawHtml(list.Product.Description);
                if (list.Product.Description.Length > 100)
                {
                    list.Product.Description = list.Product.Description.Substring(0, 99) + "...";
                }
            }
            return(View(ShoppingCartVm));
        }
Exemple #2
0
        public async Task <IActionResult> Create(Order viewModel)
        {
            var items = await _shoppingCart.GetShoppingCartItems();

            _shoppingCart.ShoppingCartItems = items;
            shoppingCartViewModel           = new ShoppingCartVm
            {
                ShoppingCart      = _shoppingCart,
                ShoppingCartTotal = await _shoppingCart.GetShoppingCartTotal()
            };

            if (_shoppingCart.ShoppingCartItems.Count == 0)
            {
                ModelState.AddModelError("", "Your cart is empty.");
            }

            if (ModelState.IsValid)
            {
                var shoppingCartItems = _shoppingCart.ShoppingCartItems;
                viewModel.OrderTotal = await _shoppingCart.GetShoppingCartTotal();

                await _orderService.Add(viewModel, shoppingCartItems);

                await _shoppingCart.ClearCart(HttpContext.Session.GetString("CartId"));

                return(RedirectToAction(nameof(Index)));
            }

            if (User.IsInRole(Roles.Client))
            {
                return(View(viewModel));
            }
            return(View("~/Views/Checkout/ManageCreate.cshtml", viewModel));
        }
        public IActionResult Summary()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            ShoppingCartVm = new ShoppingCartVm()
            {
                OrderHeader = new Models.OrderHeader(),
                ListCart    = _unitofWork.ShoppingCart.GetAll(c => c.ApplicationUserId == claim.Value, includeProperties: "Product")
            };


            ShoppingCartVm.OrderHeader.ApplicationUser = _unitofWork.ApplicationUser
                                                         .GetFirstOrDefault(c => c.Id == claim.Value,
                                                                            includeProperties: "Company");

            foreach (var list in ShoppingCartVm.ListCart)
            {
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.Product.Price,
                                                        list.Product.Price50, list.Product.Price100);
                ShoppingCartVm.OrderHeader.OrderTotal += (list.Price * list.Count);
            }
            ShoppingCartVm.OrderHeader.Name          = ShoppingCartVm.OrderHeader.ApplicationUser.Name;
            ShoppingCartVm.OrderHeader.PhoneNumber   = ShoppingCartVm.OrderHeader.ApplicationUser.PhoneNumber;
            ShoppingCartVm.OrderHeader.StreetAddress = ShoppingCartVm.OrderHeader.ApplicationUser.StreetAddress;
            ShoppingCartVm.OrderHeader.City          = ShoppingCartVm.OrderHeader.ApplicationUser.City;
            ShoppingCartVm.OrderHeader.State         = ShoppingCartVm.OrderHeader.ApplicationUser.State;
            ShoppingCartVm.OrderHeader.PostalCode    = ShoppingCartVm.OrderHeader.ApplicationUser.PostalCode;

            return(View(ShoppingCartVm));
        }
        public async Task <ShoppingCartVm> GetShoppingCart(ShoppingCart cart)
        {
            var result = new ShoppingCartVm
            {
                CartItems = await cart.GetCartItems(),
                CartTotal = await cart.GetTotal()
            };

            return(result);
        }
        public IActionResult Index()
        {
            var cart = _shoppingCart.GetCart();

            var vm = new ShoppingCartVm
            {
                ShoppingCart = cart
            };

            return(View(vm));
        }
        public async Task <IActionResult> Index()
        {
            var items = await _shoppingCart.GetShoppingCartItems();

            _shoppingCart.ShoppingCartItems = items.ToList();
            shoppingCartViewModel           = new ShoppingCartVm
            {
                ShoppingCart      = _shoppingCart,
                ShoppingCartTotal = await _shoppingCart.GetShoppingCartTotal()
            };
            return(View(shoppingCartViewModel));
        }
        public IViewComponentResult Invoke()
        {
            var items = _shoppingCart.GetShoppingCartItems();

            _shoppingCart.ShoppingCartItemsList = items;
            var shoppingCartVm = new ShoppingCartVm
            {
                ShoppingCart      = _shoppingCart,
                ShoppingCartTotal = _shoppingCart.GetShoppingCartTotal()
            };

            return(View(shoppingCartVm));
        }
Exemple #8
0
        public IActionResult GetItems()
        {
            var items = _shoppingCart.GetShoppingCartItems();

            _shoppingCart.ShoppingCartItemsList = items;
            var sCVM = new ShoppingCartVm
            {
                ShoppingCart      = _shoppingCart,
                ShoppingCartTotal = _shoppingCart.GetShoppingCartTotal()
            };

            return(View(sCVM));
        }
Exemple #9
0
        //public ShoppingCartController(ApplicationDbContext context)
        //{
        //    _context = context;
        //}

        public ViewResult Index()
        {
            var items = _shoppingCartContext.GetShoppingCartItems();

            _shoppingCartContext.ShoppingCartItems = items;

            var shoppingCartViewModel = new ShoppingCartVm
            {
                ShoppingCart      = _shoppingCartContext,
                ShoppingCartTotal = _shoppingCartContext.GetShoppingCartTotal()
            };

            return(View(shoppingCartViewModel));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var items = await _shoppingCart.GetShoppingCartItems();

            _shoppingCart.ShoppingCartItems = items;

            var shoppingCartViewModel = new ShoppingCartVm
            {
                ShoppingCart      = _shoppingCart,
                ShoppingCartTotal = await _shoppingCart.GetShoppingCartTotal()
            };

            return(View(shoppingCartViewModel));
        }
Exemple #11
0
        public IActionResult Index()
        {
            var vm = new ShoppingCartVm();

            List <CartItemVm> items = new List <CartItemVm>();

            foreach (var cartItem in _cartService.GetCartItems(GetSessionId()))
            {
                var product = _productService.GetProduct(cartItem.ProductId);
                items.Add(new CartItemVm
                {
                    Id         = product.Id,
                    Name       = product.Name,
                    Cost       = product.Cost.ToString("C"),
                    customcost = product.Cost
                });
            }
            vm.CartItems    = items;
            vm.TotalCost    = (items.Sum(x => x.customcost));
            ViewBag.Totalct = vm.TotalCost;
            return(View(vm));
        }