public async Task <IActionResult> OnGetAsync(string productId)
        {
            if (string.IsNullOrEmpty(productId))
            {
                return(NotFound());
            }

            Product = await _catalogApi.GetProduct(productId);

            if (Product == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public async Task <IActionResult> UpdateAsync(string id)
        {
            var catalogModel = await _catalogApi.GetProduct(id);


            AddCatalogModel addCatalogModel = new AddCatalogModel
            {
                Id          = catalogModel.Id,
                Name        = catalogModel.Name,
                Description = catalogModel.Description,
                Price       = catalogModel.Price,
                Category    = catalogModel.Category,
                Summary     = catalogModel.Summary
            };

            return(View(addCatalogModel));
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAddToCartAsync(string productId)
        {
            //if (!User.Identity.IsAuthenticated)
            //    return RedirectToPage("./Account/Login", new { area = "Identity" });
            var product = await _catalogApi.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"));
        }
Esempio n. 4
0
        public async Task <IActionResult> OnGetAsync(int?productId)
        {
            if (productId == null)
            {
                return(NotFound());
            }

            Product = await _catalogApi.GetProduct(productId.Value.ToString());

            if (Product == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public async Task <IActionResult> OnPostAddToCartAsync(string productId)
        {
            Models.ProductModel product = await _catalogApi.GetProduct(productId);

            string      username = "******";
            BasketModel basket   = await _basketApi.GetBasket(username);

            basket.Items.Add(new BasketItemModel
            {
                ProductId   = productId,
                ProductName = product.Name,
                Price       = product.Price,
                Quantity    = 1,
                Color       = "Black"
            });
            basket = await _basketApi.CreateBasket(basket);

            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" });

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

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

            return(RedirectToPage("Cart"));
        }