// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(Category.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(string[] selectedCategories) { var newProduct = new Product(); if (selectedCategories != null) { newProduct.ProductCategories = new List <ProductCategory>(); foreach (var cat in selectedCategories) { var catToAdd = new ProductCategory { CategoryID = int.Parse(cat) }; newProduct.ProductCategories.Add(catToAdd); } } if (await TryUpdateModelAsync <Product>( newProduct, "Product", i => i.Denumire, i => i.Descriere, i => i.Pret, i => i.DataAdaugarii, i => i.SellerID)) { _context.Product.Add(newProduct); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCategoryData(_context, newProduct); return(Page()); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.ProductCategory.Add(ProductCategory); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Category = await _context.Category.FindAsync(id); if (Category != null) { _context.Category.Remove(Category); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Seller = await _context.Seller.FindAsync(id); if (Seller != null) { _context.Seller.Remove(Seller); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Product = await _context.Product.FindAsync(id); if (Product != null) { _context.Product.Remove(Product); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(int?id, string[] selectedCategories) { if (id == null) { return(NotFound()); } var productToUpdate = await _context.Product .Include(i => i.Seller) .Include(i => i.ProductCategories) .ThenInclude(i => i.Category) .FirstOrDefaultAsync(s => s.ID == id); if (productToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Product> (productToUpdate, "Product", i => i.Denumire, i => i.Descriere, i => i.Pret, i => i.DataAdaugarii, i => i.SellerID) ) { UpdateProductCategories( _context, selectedCategories, productToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } //Apelam UpdateProductCategories pentru a aplica informatiile din checkboxuri la entitatea Products care //este editata UpdateProductCategories(_context, selectedCategories, productToUpdate); PopulateAssignedCategoryData(_context, productToUpdate); return(Page()); }