diff --git a/RazorPagesMovie/Data/RazorPagesMovieContext.cs b/RazorPagesMovie/Data/RazorPagesMovieContext.cs index 59ae158..8d84a09 100644 --- a/RazorPagesMovie/Data/RazorPagesMovieContext.cs +++ b/RazorPagesMovie/Data/RazorPagesMovieContext.cs @@ -4,7 +4,6 @@ namespace RazorPagesMovie.Data; public class RazorPagesMovieContext(DbContextOptions options) : DbContext(options) { - public DbSet Movie { get; set; } = default!; public DbSet AdminUser { get; set; } = default!; public DbSet ContactMessage { get; set; } = default!; } \ No newline at end of file diff --git a/RazorPagesMovie/Migrations/20260826122916_DropMovieTable.Designer.cs b/RazorPagesMovie/Migrations/20260826122916_DropMovieTable.Designer.cs new file mode 100644 index 0000000..1158aa7 --- /dev/null +++ b/RazorPagesMovie/Migrations/20260826122916_DropMovieTable.Designer.cs @@ -0,0 +1,91 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using RazorPagesMovie.Data; + +#nullable disable + +namespace RazorPagesMovie.Migrations +{ + [DbContext(typeof(RazorPagesMovieContext))] + [Migration("20260826122916_DropMovieTable")] + partial class DropMovieTable + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.28") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("RazorPagesMovie.Models.AdminUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("AdminUser"); + }); + + modelBuilder.Entity("RazorPagesMovie.Models.ContactMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(5000) + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("NotificationSent") + .HasColumnType("bit"); + + b.Property("Phone") + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("SentAt") + .HasColumnType("datetime2"); + + b.Property("Subject") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + b.HasKey("Id"); + + b.ToTable("ContactMessage"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/RazorPagesMovie/Migrations/20260826122916_DropMovieTable.cs b/RazorPagesMovie/Migrations/20260826122916_DropMovieTable.cs new file mode 100644 index 0000000..16ace4e --- /dev/null +++ b/RazorPagesMovie/Migrations/20260826122916_DropMovieTable.cs @@ -0,0 +1,39 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace RazorPagesMovie.Migrations +{ + /// + public partial class DropMovieTable : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Movie"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Movie", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Genre = table.Column(type: "nvarchar(30)", maxLength: 30, nullable: false), + Price = table.Column(type: "decimal(18,2)", nullable: false), + Rating = table.Column(type: "nvarchar(5)", maxLength: 5, nullable: false), + ReleaseDate = table.Column(type: "datetime2", nullable: false), + Title = table.Column(type: "nvarchar(60)", maxLength: 60, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Movie", x => x.Id); + }); + } + } +} diff --git a/RazorPagesMovie/Migrations/RazorPagesMovieContextModelSnapshot.cs b/RazorPagesMovie/Migrations/RazorPagesMovieContextModelSnapshot.cs index 8e1d911..f59b5d5 100644 --- a/RazorPagesMovie/Migrations/RazorPagesMovieContextModelSnapshot.cs +++ b/RazorPagesMovie/Migrations/RazorPagesMovieContextModelSnapshot.cs @@ -82,40 +82,6 @@ namespace RazorPagesMovie.Migrations b.ToTable("ContactMessage"); }); - - modelBuilder.Entity("RazorPagesMovie.Models.Movie", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Genre") - .IsRequired() - .HasMaxLength(30) - .HasColumnType("nvarchar(30)"); - - b.Property("Price") - .HasColumnType("decimal(18, 2)"); - - b.Property("Rating") - .IsRequired() - .HasMaxLength(5) - .HasColumnType("nvarchar(5)"); - - b.Property("ReleaseDate") - .HasColumnType("datetime2"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(60) - .HasColumnType("nvarchar(60)"); - - b.HasKey("Id"); - - b.ToTable("Movie"); - }); #pragma warning restore 612, 618 } } diff --git a/RazorPagesMovie/Models/Movie.cs b/RazorPagesMovie/Models/Movie.cs deleted file mode 100644 index 43ffc9e..0000000 --- a/RazorPagesMovie/Models/Movie.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace RazorPagesMovie.Models; - -public class Movie -{ - public int Id { get; set; } - - [StringLength(60, MinimumLength = 3)] - [Required] - public string Title { get; set; } = string.Empty; - - [Display(Name = "Release Date")] - [DataType(DataType.Date)] - public DateTime ReleaseDate { get; set; } - - [Range(1, 100)] - [DataType(DataType.Currency)] - [Column(TypeName = "decimal(18, 2)")] - public decimal Price { get; set; } - - [RegularExpression(@"^[A-Z]+[a-zA-Z\s]*$")] - [Required] - [StringLength(30)] - public string Genre { get; set; } = string.Empty; - - [RegularExpression(@"^[A-Z]+[a-zA-Z0-9""'\s-]*$")] - [StringLength(5)] - [Required] - public string Rating { get; set; } = string.Empty; -} \ No newline at end of file diff --git a/RazorPagesMovie/Pages/MoviePages/Create.cshtml b/RazorPagesMovie/Pages/MoviePages/Create.cshtml deleted file mode 100644 index 3449ce3..0000000 --- a/RazorPagesMovie/Pages/MoviePages/Create.cshtml +++ /dev/null @@ -1,54 +0,0 @@ -@page -@model RazorPagesMovie.Pages.MoviePages.CreateModel - -@{ - ViewData["Title"] = "Create"; -} - -

Create

- -

Movie

-
-
-
-
-
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- -
-
-
-
- - - -@section Scripts { - @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} -} diff --git a/RazorPagesMovie/Pages/MoviePages/Create.cshtml.cs b/RazorPagesMovie/Pages/MoviePages/Create.cshtml.cs deleted file mode 100644 index 12d2586..0000000 --- a/RazorPagesMovie/Pages/MoviePages/Create.cshtml.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.EntityFrameworkCore; -using RazorPagesMovie.Data; -using RazorPagesMovie.Models; - -namespace RazorPagesMovie.Pages.MoviePages; - -public class CreateModel : PageModel -{ - private readonly RazorPagesMovieContext _context; - - public CreateModel(RazorPagesMovieContext context) - { - _context = context; - } - - public IActionResult OnGet() - { - return Page(); - } - - [BindProperty] - public Movie Movie { get; set; } = default!; - - // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD. - public async Task OnPostAsync() - { - if (!ModelState.IsValid) - { - return Page(); - } - - _context.Movie.Add(Movie); - await _context.SaveChangesAsync(); - - return RedirectToPage("./Index"); - } -} diff --git a/RazorPagesMovie/Pages/MoviePages/Delete.cshtml b/RazorPagesMovie/Pages/MoviePages/Delete.cshtml deleted file mode 100644 index 2b4f292..0000000 --- a/RazorPagesMovie/Pages/MoviePages/Delete.cshtml +++ /dev/null @@ -1,51 +0,0 @@ -@page "{id:int}" -@model RazorPagesMovie.Pages.MoviePages.DeleteModel - -@{ - ViewData["Title"] = "Delete"; -} - -

Delete

- -

Are you sure you want to delete this?

-
-

RazorPagesMovie.Models.Movie

-
-
-
- @Html.DisplayNameFor(model => model.Movie.Title) -
-
- @Html.DisplayFor(model => model.Movie.Title) -
-
- @Html.DisplayNameFor(model => model.Movie.ReleaseDate) -
-
- @Html.DisplayFor(model => model.Movie.ReleaseDate) -
-
- @Html.DisplayNameFor(model => model.Movie.Genre) -
-
- @Html.DisplayFor(model => model.Movie.Genre) -
-
- @Html.DisplayNameFor(model => model.Movie.Price) -
-
- @Html.DisplayFor(model => model.Movie.Price) -
-
- @Html.DisplayNameFor(model => model.Movie.Rating) -
-
- @Html.DisplayFor(model => model.Movie.Rating) -
-
-
- - | - Back to List -
-
diff --git a/RazorPagesMovie/Pages/MoviePages/Delete.cshtml.cs b/RazorPagesMovie/Pages/MoviePages/Delete.cshtml.cs deleted file mode 100644 index 9155e4e..0000000 --- a/RazorPagesMovie/Pages/MoviePages/Delete.cshtml.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.EntityFrameworkCore; -using RazorPagesMovie.Data; -using RazorPagesMovie.Models; - -namespace RazorPagesMovie.Pages.MoviePages; - -public class DeleteModel : PageModel -{ - private readonly RazorPagesMovieContext _context; - - public DeleteModel(RazorPagesMovieContext context) - { - _context = context; - } - - [BindProperty] - public Movie Movie { get; set; } = default!; - - public async Task OnGetAsync(int? id) - { - if (id is null) - { - return NotFound(); - } - - var movie = await _context.Movie.FirstOrDefaultAsync(m => m.Id == id); - if (movie is null) - { - return NotFound(); - } - else - { - Movie = movie; - } - - return Page(); - } - - public async Task OnPostAsync(int? id) - { - if (id is null) - { - return NotFound(); - } - - var movie = await _context.Movie.FindAsync(id); - if (movie != null) - { - Movie = movie; - _context.Movie.Remove(Movie); - await _context.SaveChangesAsync(); - } - - return RedirectToPage("./Index"); - } -} diff --git a/RazorPagesMovie/Pages/MoviePages/Details.cshtml b/RazorPagesMovie/Pages/MoviePages/Details.cshtml deleted file mode 100644 index da4c1dd..0000000 --- a/RazorPagesMovie/Pages/MoviePages/Details.cshtml +++ /dev/null @@ -1,49 +0,0 @@ -@page "{id:int}" -@model RazorPagesMovie.Pages.MoviePages.DetailsModel - -@{ - ViewData["Title"] = "Details"; -} - -

Details

- -
-

Movie

-
-
-
- @Html.DisplayNameFor(model => model.Movie.Title) -
-
- @Html.DisplayFor(model => model.Movie.Title) -
-
- @Html.DisplayNameFor(model => model.Movie.ReleaseDate) -
-
- @Html.DisplayFor(model => model.Movie.ReleaseDate) -
-
- @Html.DisplayNameFor(model => model.Movie.Genre) -
-
- @Html.DisplayFor(model => model.Movie.Genre) -
-
- @Html.DisplayNameFor(model => model.Movie.Price) -
-
- @Html.DisplayFor(model => model.Movie.Price) -
-
- @Html.DisplayNameFor(model => model.Movie.Rating) -
-
- @Html.DisplayFor(model => model.Movie.Rating) -
-
-
- diff --git a/RazorPagesMovie/Pages/MoviePages/Details.cshtml.cs b/RazorPagesMovie/Pages/MoviePages/Details.cshtml.cs deleted file mode 100644 index faf98de..0000000 --- a/RazorPagesMovie/Pages/MoviePages/Details.cshtml.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.EntityFrameworkCore; -using RazorPagesMovie.Data; -using RazorPagesMovie.Models; - -namespace RazorPagesMovie.Pages.MoviePages; - -public class DetailsModel : PageModel -{ - private readonly RazorPagesMovieContext _context; - public DetailsModel(RazorPagesMovieContext context) - { - _context = context; - } - - public Movie Movie { get; set; } = default!; - - public async Task OnGetAsync(int? id) - { - if (id is null) - { - return NotFound(); - } - - var movie = await _context.Movie.FirstOrDefaultAsync(m => m.Id == id); - if (movie is null) - { - return NotFound(); - } - else - { - Movie = movie; - } - - return Page(); - } -} diff --git a/RazorPagesMovie/Pages/MoviePages/Edit.cshtml b/RazorPagesMovie/Pages/MoviePages/Edit.cshtml deleted file mode 100644 index 9f34c13..0000000 --- a/RazorPagesMovie/Pages/MoviePages/Edit.cshtml +++ /dev/null @@ -1,55 +0,0 @@ -@page "{id:int}" -@model RazorPagesMovie.Pages.MoviePages.EditModel - -@{ - ViewData["Title"] = "Edit"; -} - -

Edit

- -

Movie

-
-
-
-
-
- -
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- -
-
-
-
- - - -@section Scripts { - @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} -} diff --git a/RazorPagesMovie/Pages/MoviePages/Edit.cshtml.cs b/RazorPagesMovie/Pages/MoviePages/Edit.cshtml.cs deleted file mode 100644 index b30c04e..0000000 --- a/RazorPagesMovie/Pages/MoviePages/Edit.cshtml.cs +++ /dev/null @@ -1,71 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.EntityFrameworkCore; -using RazorPagesMovie.Data; -using RazorPagesMovie.Models; - -namespace RazorPagesMovie.Pages.MoviePages; - -public class EditModel : PageModel -{ - private readonly RazorPagesMovieContext _context; - - public EditModel(RazorPagesMovieContext context) - { - _context = context; - } - - [BindProperty] - public Movie Movie { get; set; } = default!; - - public async Task OnGetAsync(int? id) - { - if (id is null) - { - return NotFound(); - } - - var movie = await _context.Movie.FirstOrDefaultAsync(m => m.Id == id); - if (movie is null) - { - return NotFound(); - } - Movie = movie; - 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 OnPostAsync() - { - if (!ModelState.IsValid) - { - return Page(); - } - - _context.Attach(Movie).State = EntityState.Modified; - - try - { - await _context.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!MovieExists(Movie.Id)) - { - return NotFound(); - } - else - { - throw; - } - } - - return RedirectToPage("./Index"); - } - - private bool MovieExists(int id) - { - return _context.Movie.Any(e => e.Id == id); - } -} diff --git a/RazorPagesMovie/Pages/MoviePages/Index.cshtml b/RazorPagesMovie/Pages/MoviePages/Index.cshtml deleted file mode 100644 index 86e3834..0000000 --- a/RazorPagesMovie/Pages/MoviePages/Index.cshtml +++ /dev/null @@ -1,63 +0,0 @@ -@page -@model RazorPagesMovie.Pages.MoviePages.IndexModel - -@{ - ViewData["Title"] = "Index"; -} - -

Index

- -

- Create New -

-
-

- - - -

-
- - - - - - - - - - - -@foreach (var item in Model.Movie) { - - - - - - - -} - -
- @Html.DisplayNameFor(model => model.Movie[0].Title) - - @Html.DisplayNameFor(model => model.Movie[0].ReleaseDate) - - @Html.DisplayNameFor(model => model.Movie[0].Genre) - - @Html.DisplayNameFor(model => model.Movie[0].Price) -
- @Html.DisplayFor(model => item.Title) - - @Html.DisplayFor(model => item.ReleaseDate) - - @Html.DisplayFor(model => item.Genre) - - @Html.DisplayFor(model => item.Price) - - Edit | - Details | - Delete -
diff --git a/RazorPagesMovie/Pages/MoviePages/Index.cshtml.cs b/RazorPagesMovie/Pages/MoviePages/Index.cshtml.cs deleted file mode 100644 index 8250c75..0000000 --- a/RazorPagesMovie/Pages/MoviePages/Index.cshtml.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.AspNetCore.Mvc.Rendering; -using Microsoft.EntityFrameworkCore; -using RazorPagesMovie.Models; - -namespace RazorPagesMovie.Pages.MoviePages; - -public class IndexModel : PageModel -{ - private readonly RazorPagesMovie.Data.RazorPagesMovieContext _context; - - public IndexModel(RazorPagesMovie.Data.RazorPagesMovieContext context) - { - _context = context; - } - - public IList Movie { get; set; } = default!; - - [BindProperty(SupportsGet = true)] - public string? SearchString { get; set; } - - public SelectList? Genres { get; set; } - - [BindProperty(SupportsGet = true)] - public string? MovieGenre { get; set; } - - public async Task OnGetAsync() - { - IQueryable genreQuery = from m in _context.Movie - orderby m.Genre - select m.Genre; - - var movies = from m in _context.Movie select m; - - if (!string.IsNullOrEmpty(SearchString)) - { - movies = movies.Where(s => s.Title.Contains(SearchString)); - } - - if (!string.IsNullOrEmpty(MovieGenre)) - { - movies = movies.Where(x => x.Genre == MovieGenre); - } - - Genres = new SelectList(await genreQuery.Distinct().ToListAsync()); - Movie = await movies.ToListAsync(); - } -} \ No newline at end of file diff --git a/RazorPagesMovie/SeedData/SeedData.cs b/RazorPagesMovie/SeedData/SeedData.cs index d3ae35a..70ba601 100644 --- a/RazorPagesMovie/SeedData/SeedData.cs +++ b/RazorPagesMovie/SeedData/SeedData.cs @@ -12,22 +12,11 @@ public static class SeedData using (var context = new RazorPagesMovieContext( serviceProvider.GetRequiredService>())) { - if (context == null || context.Movie == null) + if (context == null) { throw new ArgumentNullException("Null RazorPagesMovieContext"); } - if (!context.Movie.Any()) - { - context.Movie.AddRange( -new Movie { Title = "When Harry Met Sally", ReleaseDate = DateTime.Parse("1989-2-12"), Genre = "Romantic Comedy", Price = 7.99M, Rating = "R" }, -new Movie { Title = "Ghostbusters", ReleaseDate = DateTime.Parse("1984-3-13"), Genre = "Comedy", Price = 8.99M, Rating = "G" }, -new Movie { Title = "Ghostbusters 2", ReleaseDate = DateTime.Parse("1986-2-23"), Genre = "Comedy", Price = 9.99M, Rating = "G" }, -new Movie { Title = "Rio Bravo", ReleaseDate = DateTime.Parse("1959-4-15"), Genre = "Western", Price = 3.99M, Rating = "NR" } - ); - context.SaveChanges(); - } - if (!context.AdminUser.Any()) { var accounts = serviceProvider.GetRequiredService()