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.CategoryID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Categories.Add(Category); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Category = await _context.Categories.FindAsync(id); if (Category != null) { _context.Categories.Remove(Category); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string[] selectedCategories) { if (!ModelState.IsValid) { return(Page()); } var newDanceEvent = new DanceEvent(); if (selectedCategories != null) { newDanceEvent.DanceEventCategories = new List <DanceEventCategory>(); foreach (var category in selectedCategories) { var categoryToAdd = new DanceEventCategory { CategoryID = int.Parse(category) }; newDanceEvent.DanceEventCategories.Add(categoryToAdd); } ; } if (await TryUpdateModelAsync <DanceEvent>( newDanceEvent, "danceevent", e => e.DanceEventName, e => e.EventDate, e => e.City, e => e.State, e => e.Website)) { _context.DanceEvents.Add(newDanceEvent); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCategoryData(_context, newDanceEvent); return(Page()); }