public async Task <IActionResult> OnPostAddToCartAsync(string productId)
        {
            //if (!User.Identity.IsAuthenticated)
            //    return RedirectToPage("./Account/Login", new { area = "Identity" });

            string userId = HttpContext.Session.GetString("userId");

            if (string.IsNullOrEmpty(userId))
            {
                return(RedirectToPage("Login", new { loginError = "Please sign in" }));
            }
            Product = await _catalogApi.GetProduct(productId);

            var item = new BasketItem
            {
                ProductId   = productId,
                Quantity    = Quantity,
                Color       = Color,
                ProductName = Product.Name,
                Price       = Product.Price
            };
            await _basketApi.AddItem(userId, item);

            return(RedirectToPage("Cart"));
        }
        public async Task <IActionResult> OnPostAddToCartAsync(string productId)
        {
            //if (!User.Identity.IsAuthenticated)
            //    return RedirectToPage("./Account/Login", new { area = "Identity" });
            var product = await _productApi.GetProduct(productId);

            var item = new CartItem()
            {
                ProductId = product.Id, ProductName = product.Name, Quantity = 1, Color = "Red", Price = product.Price
            };

            await _basketApi.AddItem("test", item);

            return(RedirectToPage("Cart"));
        }
        public async Task <IActionResult> OnPostAddToCartAsync(string productId)
        {
            //if (!User.Identity.IsAuthenticated)
            //    return RedirectToPage("./Account/Login", new { area = "Identity" });
            username = HttpContext.Session.GetString("username");
            if (string.IsNullOrEmpty(username))
            {
                return(RedirectToPage("Login", new { loginError = "Please sign in" }));
            }
            var item = await _productApi.GetProduct(productId);

            await _basketApi.AddItem(username, new CartItem { ProductId = productId, Color = "Black", Price = item.Price,
                                                              Quantity  = 1, ProductName = item.Name });

            return(RedirectToPage("Cart"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAddToCartAsync(string productId)
        {
            /*string username = HttpContext.Session.GetString("username");
             * if (string.IsNullOrEmpty(username)) return RedirectToPage("Login", new { loginError = "Please sign in" });*/
            Product = await _productApi.GetProduct(productId);

            var item = new CartItem
            {
                ProductId   = productId,
                Quantity    = Quantity,
                Color       = Color,
                ProductName = Product.Name,
                Price       = Product.Price
            };
            await _basketApi.AddItem("test", item);

            return(RedirectToPage("Cart"));
        }
        public async Task <IActionResult> OnPostAddToCartAsync(string productId)
        {
            string userId = HttpContext.Session.GetString("userId");

            if (string.IsNullOrEmpty(userId))
            {
                return(RedirectToPage("Login", new { loginError = "Please sign in" }));
            }
            var product = await _catalogApi.GetProduct(productId);

            var item = new BasketItem
            {
                ProductId   = product.Id,
                Price       = product.Price,
                ProductName = product.Name,
                Quantity    = 1
            };
            await _basketApi.AddItem(userId, item);

            return(RedirectToPage("Cart"));
        }
        public async Task <IActionResult> OnPostAddToCartAsync(string productId)
        {
            //if (!User.Identity.IsAuthenticated)
            //    return RedirectToPage("./Account/Login", new { area = "Identity" });
            if (!string.IsNullOrEmpty(productId))
            {
                var prod = await _catalogApi.GetProduct(productId);

                var prod_item = new CartItem()
                {
                    ProductId   = prod.Id,
                    ProductName = prod.Name,
                    Quantity    = Quantity,
                    Color       = Color,
                    Price       = prod.Price
                };
                await _basketApi.AddItem("test", prod_item);
            }

            return(RedirectToPage("Cart"));
        }