// 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) { if (id == null) { return(NotFound()); } var bookToUpdate = await _context.Books.FindAsync(id); if (bookToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Book>( bookToUpdate, "book", // Prefix for form value. s => s.Title, s => s.TotalPages, s => s.Rating, s => s.ISBN, s => s.DatePublished, s => s.PublisherID, s => s.AuthorID, s => s.GenreID)) { await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulatePublisherDropDownList(_context, bookToUpdate.PublisherID); PopulateAuthorDropDownList(_context, bookToUpdate.AuthorID); PopulateGenreDropDownList(_context, bookToUpdate.GenreID); 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(Genre).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GenreExists(Genre.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Publishers.Add(Publisher); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Genre = await _context.Genres.FindAsync(id); if (Genre != null) { _context.Genres.Remove(Genre); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { var emptyBook = new Book(); if (await TryUpdateModelAsync <Book>( emptyBook, "book", s => s.Title, s => s.TotalPages, s => s.Rating, s => s.ISBN, s => s.DatePublished, s => s.PublisherID, s => s.AuthorID, s => s.GenreID)) { _context.Books.Add(emptyBook); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulatePublisherDropDownList(_context, emptyBook.PublisherID); PopulateAuthorDropDownList(_context, emptyBook.AuthorID); PopulateGenreDropDownList(_context, emptyBook.GenreID); return(Page()); }