Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #nullable disable
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.AspNetCore.Mvc.RazorPages;
  8. using Microsoft.EntityFrameworkCore;
  9. using RazorMovie.Data;
  10. using RazorMovie.Models;
  11.  
  12. namespace RazorMovie.Pages.Movies
  13. {
  14. public class DeleteModel : PageModel
  15. {
  16. private readonly RazorMovie.Data.RazorMovieContext _context;
  17.  
  18. public DeleteModel(RazorMovie.Data.RazorMovieContext context)
  19. {
  20. _context = context;
  21. }
  22.  
  23. [BindProperty]
  24. public Movie Movie { get; set; }
  25.  
  26. public async Task<IActionResult> OnGetAsync(int? id)
  27. {
  28. if (id == null)
  29. {
  30. return NotFound();
  31. }
  32.  
  33. Movie = await _context.Movie.FirstOrDefaultAsync(m => m.ID == id);
  34.  
  35. if (Movie == null)
  36. {
  37. return NotFound();
  38. }
  39. return Page();
  40. }
  41.  
  42. public async Task<IActionResult> OnPostAsync(int? id)
  43. {
  44. if (id == null)
  45. {
  46. return NotFound();
  47. }
  48.  
  49. Movie = await _context.Movie.FindAsync(id);
  50.  
  51. if (Movie != null)
  52. {
  53. _context.Movie.Remove(Movie);
  54. await _context.SaveChangesAsync();
  55. }
  56.  
  57. return RedirectToPage("./Index");
  58. }
  59. }
  60. }
  61.