public IActionResult ShopCartIndex(ShopCartViewModel cart)
        {
            try
            {
                var userId = 1;
                var user   = userService.GetUserById(userId); //mudar aqui qnd ter o user

                if (cart == null || cart.Products == null || cart.Products.Count == 0)
                {
                    cart = saleService.GetCartByCustomer(user);
                }

                if (cart == null || cart.Products == null || cart.Products.Count == 0)
                {
                    return(RedirectToAction("Index"));
                }

                ViewBag.UserAdresses   = new SelectList(user.Addresses, "AddressId", "PostalCode");
                ViewBag.PaymentMethods = new SelectList(paymentService.GetPaymentMethods(), "PaymentMethodId", "Description");

                return(View("~/Views/Sale/ShopCart/Index.cshtml", cart));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
        public ViewResult Index(int id)
        {
            var items = shopCart.GetShopItems();

            shopCart.ShopCartItems = items;

            var product      = dbContext.Products.FirstOrDefault(i => i.Id == id);
            var shopCartItem = shopCart.ShopCartItems.FirstOrDefault(i => i.Product == product);

            if (shopCartItem != null)
            {
                shopCart.ShopCartItems.Remove(shopCartItem);
                dbContext.ShopCartItems.Remove(shopCartItem);
                product.ProductCountInShopCart = 0;
                dbContext.SaveChanges();
            }

            obj = new ShopCartViewModel()
            {
                ShopCart = shopCart,
                Total    = shopCart.Total()
            };
            ViewBag.ProductCount = shopCart.ProductCount();

            return(View(obj));
        }
Пример #3
0
 public IActionResult Cart(ShopCartViewModel model)
 {
     if (_shopCart.GetShopItems().Count() == 0)
     {
         ModelState.AddModelError("", "Add more products");
     }
     if (ModelState.IsValid)
     {
         Order order = model.Order;
         order.Products = JsonSerializer.Serialize <int[]>(_shopCart.GetShopItems().Select(el => el.product.Id).ToArray());
         order.Price    = _shopCart.GetShopItems().Sum(el => el.product.Price);
         List <OrderSize> sizes = new List <OrderSize>();
         foreach (var item in _shopCart.GetShopItems())
         {
             sizes.Add(new OrderSize {
                 ProductId = item.product.Id, ProductSize = item.Size
             });
         }
         order.ProductsSizes = JsonSerializer.Serialize <List <OrderSize> >(sizes);
         _db.Orders.Add(order);
         _db.SaveChanges();
         _shopCart = ShopCart.CreateNewCart(_service);
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         return(View(model));
     }
 }
Пример #4
0
        //[Route("ShopCart")]
        //[Route("ShopCart/Index")]
        public ViewResult Index()
        {
            var obj = new ShopCartViewModel {
                shopCartItems = _shopCart.GetShopCartItems()
            };

            return(View(obj));
        }
Пример #5
0
        public IActionResult Index()
        {
            var shopCart = new ShopCartViewModel()
            {
                ShopCart = _shopCart
            };

            return(View(shopCart));
        }
Пример #6
0
        public ViewResult Index()
        {
            var items = _shopCart.GetShopItems();

            _shopCart.listShopPhoneItems = items;
            var obj = new ShopCartViewModel(_shopCart);

            return(View(obj));
        }
Пример #7
0
        public ViewResult Index()
        {
            var items = _shopCart.getShopItems();

            _shopCart.listShopCartItems = items;
            var obj = new ShopCartViewModel {
                shopCart = _shopCart
            };

            return(View(obj));
        }
Пример #8
0
        public ViewResult Index()
        {
            var items = this.shopCart.GetShopItems();

            this.shopCart.ListShopItems = items;
            var obj = new ShopCartViewModel {
                ShopCart = this.shopCart
            };

            return(View(obj));
        }
Пример #9
0
        // GET: ShopCart
        public ActionResult Index()
        {
            var shopCartPosition     = manager.GetShopCart();
            var price                = manager.getShopCartPrice();
            ShopCartViewModel cartVM = new ShopCartViewModel()
            {
                shopCartPosition = shopCartPosition,
                priceOfProducts  = price,
            };

            return(View(cartVM));
        }
Пример #10
0
        public ViewResult Index()   // возвращает шаблон
        {
            var items = _shopCart.getShopItems();

            _shopCart.listShopItems = items;    // установка всех товаров, имеющихся в корзине

            var obj = new ShopCartViewModel {
                shopCart = _shopCart
            };

            return(View(obj));
        }
Пример #11
0
        public IActionResult Index()
        {
            var items = _shopcart.GetShopCartItems();

            _shopcart.Listshopcartitems = items;
            ShopCartViewModel shopCartviewmodel = new ShopCartViewModel()
            {
                shopCart = _shopcart
            };

            return(View(shopCartviewmodel));
        }
Пример #12
0
        public IActionResult Index()
        {
            var items = _shopCart.GetShopItems();

            _shopCart.ListShopItems = items;

            var obj = new ShopCartViewModel {
                ShopCart = _shopCart
            };

            return(View(obj));
        }
        public ViewResult CartView()
        {
            var items = _shopCart.GetShopItems();

            _shopCart.listShopItems = items;

            var obj = new ShopCartViewModel();

            obj.shopCart = _shopCart;

            return(View(obj));
        }
Пример #14
0
        public IViewComponentResult Invoke()
        {
            var items = _shopCart.GetShopCartItems();

            _shopCart.ShopCartItems = items;
            var shopCartViewModel = new ShopCartViewModel
            {
                ShopCart      = _shopCart,
                ShopCartTotal = _shopCart.GetShopCartTotal()
            };

            return(View(shopCartViewModel));
        }
Пример #15
0
        public ViewResult Index()
        {
            var Items = this.ShopCart.GetShopItems();

            this.ShopCart.ListShopItems = Items;

            var Object = new ShopCartViewModel
            {
                ShopCart = this.ShopCart
            };

            return(View(Object));
        }
Пример #16
0
        public ViewResult Index()
        {
            var shopItems = _shopCart.GetItems();

            _shopCart.Items = shopItems;

            var shopCart = new ShopCartViewModel
            {
                ShopCart = _shopCart
            };

            return(View(shopCart));
        }
Пример #17
0
        /* FUNKCIJA - leidzianti iskviesti HTML sablona ir atvaizduoti */
        public ViewResult Index()
        {
            var items = _shopCart.getShopItems(); /* Paima prekes (Is db) */

            _shopCart.listShopItems = items;      /* Priskiria prekes */

            var obj = new ShopCartViewModel
            {
                shopCart = _shopCart /* Priskirimas */
            };

            return(View(obj)); /* Priskirto Objekto Returninimas */
        }
Пример #18
0
        public ViewResult Index()
        {
            var items = _shopCart.GetShopCartItems();

            _shopCart.ShopCartItems = items;
            var obj = new ShopCartViewModel
            {
                ShopCart      = _shopCart,
                ShopCartTotal = _shopCart.GetShopCartTotal()
            };

            return(View(obj));
        }
Пример #19
0
        public ViewResult Index()
        {
            //var items = _shopCart.GetShopCartItems();
            // _shopCart.ListShopItems =items;
            _shopCart.ListShopItems = _shopCart.GetShopCartItems();//заполнение массива из БД

            ShopCartViewModel obj = new ShopCartViewModel()
            {
                ShopCart = _shopCart//передача корзины с заполненным массивом в корзину модели представления
            };

            return(View(obj));
        }
        public ViewResult Index() // возвращает шаблон
        {
            var items = _shopCart.getShopItems();

            _shopCart.listShopItem = items;

            var obj = new ShopCartViewModel
            {
                shopCart = _shopCart
            };

            return(View(obj));
        }
Пример #21
0
        public ViewResult index()
        {
            var items = _shopCart.GetCartItems();

            _shopCart.ToPayList = items;

            var obj = new ShopCartViewModel
            {
                shopCart = _shopCart
            };

            return(View(obj));
        }
Пример #22
0
        public IActionResult Index()
        {
            var items = _shopCart.getShopItems();

            _shopCart.ListShopItems = items;

            var obj = new ShopCartViewModel
            {
                shopCart = _shopCart,
                Price    = _shopCart.cPrice(items)
            };

            return(View(obj));
        }
Пример #23
0
        // GET: ShopCart
        public ActionResult Index()
        {
            var cart = ShopCart.GetCart(this.HttpContext);

            // Set up our ViewModel
            var viewModel = new ShopCartViewModel
            {
                CartItems = cart.GetCartItems(),
                CartTotal = cart.GetTotal()
            };

            // Return the view
            return(View(viewModel));
        }
 public ActionResult FinishSale(ShopCartViewModel model)
 {
     try
     {
         if (this.ModelState.IsValid)
         {
             var sales = saleService.FinishSale(model);
             var text  = GenerateDocumentSaleTemplate(sales);
             return(CreateDocument(text));
         }
         return(RedirectToAction("ShopCartIndex", model));
     }
     catch (System.Exception)
     {
         throw;
     }
 }
Пример #25
0
        public IActionResult Index()
        {
            // init new array of books
            List <Book> AllBookListFromCartByLoggedInUser = new List <Book>();
            double      TotalPriceCount     = 0.0;
            double      TotalShipping       = 0.0;
            int         NotificationCounter = 0;
            double      TotalWeightCount    = 0.0;

            // get logged in user id
            var userId      = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var itemsInCart = _shoppingCartService.GetAllItemsInCartByUserId(userId);

            // convert all cart items to list of books
            AllBookListFromCartByLoggedInUser = _orderService.ConvertAllItemsInCartToList(itemsInCart);
            // calculate total price of books in cart
            TotalPriceCount = _orderService.CalculateTotalPrice(TotalShipping, AllBookListFromCartByLoggedInUser);
            // notification counter for items in cart
            NotificationCounter = _shoppingCartService.GetAllItemsInCart().Count();
            // calculate total weight
            TotalWeightCount = _orderService.CalculateTotalWeight(AllBookListFromCartByLoggedInUser);

            // convert all cart items to list of books
            AllBookListFromCartByLoggedInUser = _orderService.ConvertAllItemsInCartToList(itemsInCart);

            TotalPriceCount     = TotalShipping + Math.Round(AllBookListFromCartByLoggedInUser.Sum(x => x.Price), 2);
            NotificationCounter = _shoppingCartService.GetAllItemsInCart().Count();

            var shopCartViewModel = new ShopCartViewModel()
            {
                AllBooksAddedToCartByLoggedInUser = AllBookListFromCartByLoggedInUser,
                AddToCartTotalCounter             = NotificationCounter
            };

            var subTotal      = _orderService.CalculateTotalShipping(TotalWeightCount, TotalPriceCount).Item1;
            var shippingTotal = _orderService.CalculateTotalShipping(TotalWeightCount, TotalPriceCount).Item2;
            var totalPrice    = _orderService.CalculateTotalShipping(TotalWeightCount, TotalPriceCount).Item3;

            shopCartViewModel.TotalPrice    = totalPrice;
            shopCartViewModel.SubTotal      = subTotal;
            shopCartViewModel.ShippingTotal = shippingTotal;

            ViewData["Counter"] = NotificationCounter;

            return(View(shopCartViewModel));
        }
Пример #26
0
 public IActionResult Index()
 {
     if (User.IsInRole("Admin"))
     {
         return(RedirectToAction("AdminInfo"));
     }
     else
     {
         var items = _shopCart.getShopItems();
         _shopCart.listShopItems = items;
         var obj = new ShopCartViewModel
         {
             shopCart = _shopCart
         };
         return(View(obj));
     }
 }
Пример #27
0
        public ViewResult Index()
        {
            ViewBag.Title = "basket";

            var items = _shopcart.getShopCartItems();

            _shopcart.listShopItems = items;



            var obj = new ShopCartViewModel
            {
                shopCart = _shopcart
            };

            return(View(obj));
        }
Пример #28
0
        public ViewResult Index()
        {
            var items = _shopCart.GetShopItems();

            _shopCart.ListShopItems = items;
            var obj = new ShopCartViewModel {
                ShopCart = _shopCart
            };
            int ShopCartItemsPriceSum = 0;

            foreach (var el in _shopCart.ListShopItems)
            {
                ShopCartItemsPriceSum += el.Product.Price;
            }

            ViewBag.PriceSum = ShopCartItemsPriceSum;
            return(View(obj));
        }
Пример #29
0
        public ViewResult Index()
        {
            var items = _shopCart.GetShopItems();

            _shopCart.ShopItemsList = items;

            var obj = new ShopCartViewModel
            {
                ShopCart = _shopCart
            };

            obj.SumPrice = 0;
            foreach (ShopCartItem cartItem in items)
            {
                obj.SumPrice += cartItem.instance.Price;
            }

            return(View(obj));
        }
Пример #30
0
        public IActionResult Cart()
        {
            var items = _shopCart.GetShopItems();

            _shopCart.listShopItems = items;
            Dictionary <int, string> ImgUrls = new Dictionary <int, string>();

            foreach (var item in items)
            {
                ImgUrls[item.product.Id] = JsonSerializer.Deserialize <string[]>(item.product.ImgUrls).FirstOrDefault();
            }
            var model = new ShopCartViewModel
            {
                shopCart = _shopCart,
                ImgUrls  = ImgUrls
            };

            return(View(model));
        }