コード例 #1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var productToUpdate = await _context.Products.FindAsync(id);

            if (productToUpdate == null)
            {
                return(NotFound());
            }

            if (await TryUpdateModelAsync <Product>(
                    productToUpdate,
                    "product", // Prefix for form value.
                    c => c.AverageCustomerRating, c => c.ProductCategoryID, c => c.ProductName, c => c.PricePerItem))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            // Select ProductCategoryID if TryUpdateModelAsync fails.
            PopulateCategoryDropDownList(_context, productToUpdate.ProductCategoryID);
            return(Page());
        }
コード例 #2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product = await _context.Products.FindAsync(id);

            if (Product != null)
            {
                _context.Products.Remove(Product);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            var emptyProduct = new Product();

            if (await TryUpdateModelAsync <Product>(
                    emptyProduct,
                    "product", // Prefix for form value.
                    s => s.ProductID, s => s.ProductCategoryID, s => s.ProductName, s => s.AverageCustomerRating, s => s.PricePerItem))
            {
                _context.Products.Add(emptyProduct);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            // Select DepartmentID if TryUpdateModelAsync fails.
            PopulateCategoryDropDownList(_context, emptyProduct.ProductCategoryID);
            return(Page());
        }