// 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 drinkToUpdate = await _context.Drink .Include(i => i.Store) .Include(i => i.DrinkCategories) .ThenInclude(i => i.Category) .FirstOrDefaultAsync(s => s.ID == id); if (drinkToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Drink>(drinkToUpdate, "Drink", i => i.Name, i => i.Company, i => i.Price, i => i.ExpiringDate, i => i.Store)) { UpdateDrinkCategories(_context, selectedCategories, drinkToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } UpdateDrinkCategories(_context, selectedCategories, drinkToUpdate); PopulateAssignedCategoryData(_context, drinkToUpdate); 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() { if (!ModelState.IsValid) { return(Page()); } _context.Store.Add(Store); 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()); } Store = await _context.Store.FindAsync(id); if (Store != null) { _context.Store.Remove(Store); 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(string[] selectedCategories) { var newDrink = new Drink(); if(selectedCategories != null) { newDrink.DrinkCategories = new List<DrinkCategory>(); foreach(var cat in selectedCategories) { var catToAdd = new DrinkCategory { CategoryID = int.Parse(cat) }; newDrink.DrinkCategories.Add(catToAdd); } } if(await TryUpdateModelAsync<Drink>(newDrink,"Drink",i => i.Name, i => i.Company, i => i.Price, i => i.ExpiringDate, i => i.StoreID)){ _context.Drink.Add(newDrink); await _context.SaveChangesAsync(); return RedirectToPage("./Index"); } PopulateAssignedCategoryData(_context, newDrink); return Page(); }