// 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 newBike = new Bike(); if (selectedCategories != null) { newBike.BikeCategories = new List <BikeCategory>(); foreach (var cat in selectedCategories) { var catToAdd = new BikeCategory { CategoryID = int.Parse(cat) }; newBike.BikeCategories.Add(catToAdd); } } if (await TryUpdateModelAsync <Bike>( newBike, "Bike", i => i.Series, i => i.Brand, i => i.Price, i => i.AparitionDate, i => i.Size, i => i.StoreID)) { _context.Bike.Add(newBike); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCategoryData(_context, newBike); 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.Attach(Store).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StoreExists(Store.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(int?id, string[] selectedCategories) { if (id == null) { return(NotFound()); } var bikeToUpdate = await _context.Bike .Include(i => i.Store) .Include(i => i.BikeCategories) .ThenInclude(i => i.Category) .FirstOrDefaultAsync(s => s.ID == id); if (bikeToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Bike>( bikeToUpdate, "Bike", i => i.Series, i => i.Brand, i => i.Price, i => i.AparitionDate, i => i.Size, i => i.StoreID)) { UpdateBikeCategories(_context, selectedCategories, bikeToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } //Apelam UpdateBookCategories pentru a aplica informatiile din checkboxuri la entitatea Books care //este editata UpdateBikeCategories(_context, selectedCategories, bikeToUpdate); PopulateAssignedCategoryData(_context, bikeToUpdate); 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.Category.Add(Category); 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()); } Bike = await _context.Bike.FindAsync(id); if (Bike != null) { _context.Bike.Remove(Bike); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }