Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Mvc.RazorPages;
  7. using Microsoft.AspNetCore.Mvc.Rendering;
  8. using RazorPagesMovies.Models;
  9. using RazorPagesMovies.Movies;
  10.  
  11. namespace RazorPagesMovies.Pages.Movies
  12. {
  13.     public class CreateModel : PageModel
  14.     {
  15.         private readonly RazorPagesMovies.Models.MoviesContext _context;
  16.  
  17.         public CreateModel(RazorPagesMovies.Models.MoviesContext context)
  18.         {
  19.             _context = context;
  20.         }
  21.  
  22.         public IActionResult OnGet()
  23.         {
  24.             return Page();
  25.         }
  26.  
  27.         [BindProperty]
  28.         public Movie Movie { get; set; }
  29.  
  30.         // To protect from overposting attacks, please enable the specific properties you want to bind to, for
  31.         // more details see https://aka.ms/RazorPagesCRUD.
  32.         public async Task<IActionResult> OnPostAsync()
  33.         {
  34.             if (!ModelState.IsValid)
  35.             {
  36.                 return Page();
  37.             }
  38.  
  39.             _context.Movie.Add(Movie);
  40.             await _context.SaveChangesAsync();
  41.  
  42.             return RedirectToPage("./Index");
  43.         }
  44.     }
  45. }
  46.