// 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 newProdus = new Produs(); if (selectedCategories != null) { newProdus.CategoriiProdus = new List <CategorieProdus>(); foreach (var cat in selectedCategories) { var catToAdd = new CategorieProdus { CategorieID = int.Parse(cat) }; newProdus.CategoriiProdus.Add(catToAdd); } } if (await TryUpdateModelAsync <Produs>(newProdus, "Produs", i => i.Denumire, i => i.Brand, i => i.Pret, i => i.DataFabricarii, i => i.StatusID)) { _context.Produs.Add(newProdus); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCategoryData(_context, newProdus); return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } CategorieProdus = await _context.CategorieProdus.FindAsync(id); if (CategorieProdus != null) { _context.CategorieProdus.Remove(CategorieProdus); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } CategorieProdus = await _context.CategorieProdus .Include(c => c.Categorie) .Include(c => c.Produs).FirstOrDefaultAsync(m => m.ID == id); if (CategorieProdus == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } CategorieProdus = await _context.CategorieProdus .Include(c => c.Categorie) .Include(c => c.Produs).FirstOrDefaultAsync(m => m.ID == id); if (CategorieProdus == null) { return(NotFound()); } ViewData["CategorieID"] = new SelectList(_context.Categorie, "ID", "NumeCategorie"); ViewData["ProdusID"] = new SelectList(_context.Produs, "ID", "ProdusProducator"); return(Page()); }
public int NumarProduse(CategorieProdus categorie) { var count = Produse.Count(p => p.Categorie == categorie); return(count); }