MovieGenres { get; set; }
- public Movie Movie { get; set; }
+ public int? Id { get; set; }
+
+ [Required]
+ [StringLength(255)]
+ public string Name { get; set; }
+
+ [Required]
+ [Display(Name = "Release Date")]
+ public DateTime? ReleaseDate { get; set; }
+
+ [Required]
+ [Range(1, 20)]
+ [Display(Name = "Number In Stock")]
+ public int? NumberInStock { get; set; }
+
+ [Display(Name = "Genre")]
+ [Required]
+ public byte? MovieGenreId { get; set; }
+
+ public string Title
+ {
+ get
+ {
+ return (Id != 0) ? "Edit Movie":"New Movie";
+ }
+ }
+
+ public MovieFormViewModel()
+ {
+ Id = 0;
+ }
+ public MovieFormViewModel(Movie movie)
+ {
+ Id = movie.Id;
+ Name = movie.Name;
+ ReleaseDate = movie.ReleaseDate;
+ NumberInStock = movie.NumberInStock;
+ MovieGenreId = movie.MovieGenreId;
+ }
}
}
\ No newline at end of file
diff --git a/Vidly/Views/Customers/CustomerForm.cshtml b/Vidly/Views/Customers/CustomerForm.cshtml
index 3765a25..8ab0555 100644
--- a/Vidly/Views/Customers/CustomerForm.cshtml
+++ b/Vidly/Views/Customers/CustomerForm.cshtml
@@ -17,7 +17,7 @@ else
@using (@Html.BeginForm("Save", "Customers"))
{
- @Html.ValidationSummary(true, "Please fix the following errors.")
+ @Html.ValidationSummary(true, "Var snäll och åtgärda felen.")
@Html.LabelFor(m => m.Customer.Name)
@Html.TextBoxFor(m => m.Customer.Name, new { @class = "form-control" })
@@ -39,6 +39,12 @@ else
@Html.HiddenFor(m => m.Customer.Id)
+ @Html.AntiForgeryToken();
}
+
+@section scripts
+{
+ @Scripts.Render("~/bundles/jqueryval")
+}
diff --git a/Vidly/Views/Movies/MovieForm.cshtml b/Vidly/Views/Movies/MovieForm.cshtml
index 4af3107..67ed994 100644
--- a/Vidly/Views/Movies/MovieForm.cshtml
+++ b/Vidly/Views/Movies/MovieForm.cshtml
@@ -5,33 +5,39 @@
}
-@if (Model.Movie.Id == null || Model.Movie.Id == 0)
-{
- New Movie
-}
-else
-{
- Edit Movie
-}
+ @Model.Title
+
@using (Html.BeginForm("Save", "Movies"))
{
+ @Html.ValidationSummary(true, "Var snäll och åtgärda felen.")
- @Html.LabelFor(m => m.Movie.Name)
- @Html.TextBoxFor(m => m.Movie.Name, new { @class = "form-control" })
+ @Html.LabelFor(m => m.Name)
+ @Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
+ @Html.ValidationMessageFor(m => m.Name)
- @Html.LabelFor(m => m.Movie.ReleaseDate)
- @Html.TextBoxFor(m => m.Movie.ReleaseDate, "{0:d MMM yyyy}", new { @class = "form-control" })
+ @Html.LabelFor(m => m.ReleaseDate)
+ @Html.TextBoxFor(m => m.ReleaseDate, "{0:d MMM yyyy}", new { @class = "form-control" })
+ @Html.ValidationMessageFor(m => m.ReleaseDate)
- @Html.LabelFor(m => m.Movie.MovieGenreId)
- @Html.DropDownListFor(m => m.Movie.MovieGenreId, new SelectList(Model.MovieGenres, "Id", "Name"), "Select Genre Type", new { @class = "form-control" })
+ @Html.LabelFor(m => m.MovieGenreId)
+ @Html.DropDownListFor(m => m.MovieGenreId, new SelectList(Model.MovieGenres, "Id", "Name"), "Select Genre Type", new { @class = "form-control" })
+ @Html.ValidationMessageFor(m => m.MovieGenreId)
+
- @Html.LabelFor(m => m.Movie.NumberInStock)
- @Html.TextBoxFor(m => m.Movie.NumberInStock, new { @class = "form-control" })
+ @Html.LabelFor(m => m.NumberInStock)
+ @Html.TextBoxFor(m => m.NumberInStock, new { @class = "form-control" })
+ @Html.ValidationMessageFor(m => m.NumberInStock)
-@Html.HiddenFor(m=>m.Movie.Id)
+ @Html.HiddenFor(m => m.Id)
+ @Html.AntiForgeryToken();
-}
\ No newline at end of file
+}
+
+@section scripts
+{
+ @Scripts.Render("~/bundles/jqueryval")
+}