Esempio n. 1
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (Product.ProductId > 0)
            {
                Product.ImgPath = Product.ImgPath ?? Utilities.Utilities.AddImageFromFile(Product, webHostEnvironment.WebRootPath, Image);

                productData.Update(Product);
            }
            else
            {
                CreateProduct();
            }

            productData.Commit();

            TempData["Message"] = "Product saved!";
            return(RedirectToPage("./Details", new { productId = Product.ProductId }));
        }
Esempio n. 2
0
        public IActionResult OnPost(int productId)
        {
            var product = productData.Delete(productId);

            if (product == null)
            {
                return(RedirectToPage("./NotFound"));
            }
            var photos = productData.GetPhotosById(productId);

            if (photos != null)
            {
                foreach (Photo photo in photos)
                {
                    string filePhotoPath = Path.Combine(webHostEnvironment.WebRootPath,
                                                        "images", $"{product.Id}", photo.Path);
                    System.IO.File.Delete(filePhotoPath);
                }
            }
            productData.Commit();

            TempData["Message"] = $"Product {product.Name} has been successfully deleted.";
            return(RedirectToPage("./List"));
        }
Esempio n. 3
0
        public IActionResult OnPost(int id)
        {
            //var category = categoryData.GetCategoryById(Product.CategoryId.Value);
            //Product.Category = category;



            Product = productData.DeleteProduct(id);

            var path = Path.Combine(@"wwwroot/images/", $"{Product.Category.Type}/", $"{Product.Name}.jpg");

            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }

            if (Product == null)
            {
                return(RedirectToPage("./List"));
            }
            TempData["Message"] = "Product is deleted";
            productData.Commit();
            return(RedirectToPage("./List"));
        }