diff --git a/Vidly/Controllers/MoviesController.cs b/Vidly/Controllers/MoviesController.cs index c9b0aa6..a38a84c 100644 --- a/Vidly/Controllers/MoviesController.cs +++ b/Vidly/Controllers/MoviesController.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Web; using System.Web.Mvc; using Vidly.Models; +using Vidly.ViewModels; namespace Vidly.Controllers { @@ -13,11 +14,22 @@ namespace Vidly.Controllers public ActionResult Random() { var movie = new Movie() { Name = "Shrek!" }; - + var customers = new List + { + new Customer {Name="Customer 1"}, + new Customer {Name="Customer 2"} + }; //var viewResult = new ViewResult(); //viewResult.ViewData.Model = movie; - return View(movie); + var viewModel = new RandomMovieViewModel() { + Movie = movie, + Customers = customers + }; + + return View(viewModel); + + //return View(movie); //return Content("Hello World"); //return HttpNotFound(); //return new EmptyResult(); diff --git a/Vidly/Models/Customer.cs b/Vidly/Models/Customer.cs new file mode 100644 index 0000000..46af066 --- /dev/null +++ b/Vidly/Models/Customer.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Vidly.Models +{ + public class Customer + { + public int Id { get; set; } + public string Name { get; set; } + + } +} \ No newline at end of file diff --git a/Vidly/Vidly.csproj b/Vidly/Vidly.csproj index 9326d96..e5b0104 100644 --- a/Vidly/Vidly.csproj +++ b/Vidly/Vidly.csproj @@ -181,11 +181,13 @@ Global.asax + + @@ -244,6 +246,7 @@ + diff --git a/Vidly/ViewModels/RandomMovieViewModel.cs b/Vidly/ViewModels/RandomMovieViewModel.cs new file mode 100644 index 0000000..a4073f9 --- /dev/null +++ b/Vidly/ViewModels/RandomMovieViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Vidly.Models; + +namespace Vidly.ViewModels +{ + public class RandomMovieViewModel + { + public Movie Movie { get; set; } + public List Customers { get; set; } + } +} \ No newline at end of file diff --git a/Vidly/Views/Movies/Random.cshtml b/Vidly/Views/Movies/Random.cshtml index d5a7a43..fa846e4 100644 --- a/Vidly/Views/Movies/Random.cshtml +++ b/Vidly/Views/Movies/Random.cshtml @@ -1,8 +1,33 @@ -@model Vidly.Models.Movie +@model Vidly.ViewModels.RandomMovieViewModel @{ ViewBag.Title = "Random"; Layout = "~/Views/Shared/_Layout.cshtml"; } -

@Model.Name

+@** + This is a comment + on multiple lines +*@ + +@{ + var className = Model.Customers.Count > 0 ? "popular" : null; +} + + +

@Model.Movie.Name

+ +@if (Model.Customers.Count == 0) +{ + No one has rented this movie before. +} +else +{ +
    + @foreach (var customer in Model.Customers) + { +
  • @customer.Name
  • + } +
+ +} diff --git a/Vidly/Views/Shared/_Layout.cshtml b/Vidly/Views/Shared/_Layout.cshtml index ae31cd1..6092731 100644 --- a/Vidly/Views/Shared/_Layout.cshtml +++ b/Vidly/Views/Shared/_Layout.cshtml @@ -4,31 +4,13 @@ @ViewBag.Title - My ASP.NET Application + @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") - + @Html.Partial("_NavBar")
@RenderBody()
diff --git a/Vidly/Views/Shared/_LoginPartial.cshtml b/Vidly/Views/Shared/_LoginPartial.cshtml index f996508..5b960e4 100644 --- a/Vidly/Views/Shared/_LoginPartial.cshtml +++ b/Vidly/Views/Shared/_LoginPartial.cshtml @@ -3,20 +3,17 @@ { using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" })) { - @Html.AntiForgeryToken() - - + @Html.AntiForgeryToken() + } } else { -