From cd91acdf530dc6108b6e43c4e78ac7b6cb31e878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Thu, 17 Jan 2019 23:11:33 +0100 Subject: [PATCH] =?UTF-8?q?Min=20l=C3=B6sning=20p=C3=A5=20=C3=B6vningen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Vidly/App_Start/RouteConfig.cs | 2 +- Vidly/Content/Site.css | 2 +- Vidly/Controllers/CustomersController.cs | 60 ++++++++++++++++++++++++ Vidly/Controllers/MoviesController.cs | 24 +++++++++- Vidly/Vidly.csproj | 7 +++ Vidly/ViewModels/CustomersViewModel.cs | 13 +++++ Vidly/ViewModels/MoviesViewModel.cs | 13 +++++ Vidly/Views/Customers/Customer.cshtml | 10 ++++ Vidly/Views/Customers/Customers.cshtml | 23 +++++++++ Vidly/Views/Customers/Index.cshtml | 11 +++++ Vidly/Views/Movies/Movies.cshtml | 23 +++++++++ Vidly/Views/Shared/_NavBar.cshtml | 8 ++-- 12 files changed, 189 insertions(+), 7 deletions(-) create mode 100644 Vidly/Controllers/CustomersController.cs create mode 100644 Vidly/ViewModels/CustomersViewModel.cs create mode 100644 Vidly/ViewModels/MoviesViewModel.cs create mode 100644 Vidly/Views/Customers/Customer.cshtml create mode 100644 Vidly/Views/Customers/Customers.cshtml create mode 100644 Vidly/Views/Customers/Index.cshtml create mode 100644 Vidly/Views/Movies/Movies.cshtml diff --git a/Vidly/App_Start/RouteConfig.cs b/Vidly/App_Start/RouteConfig.cs index 58972ef..624cafa 100644 --- a/Vidly/App_Start/RouteConfig.cs +++ b/Vidly/App_Start/RouteConfig.cs @@ -24,7 +24,7 @@ namespace Vidly routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", - defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } + defaults: new { controller = "Customers", action = "Index", id = UrlParameter.Optional } ); } } diff --git a/Vidly/Content/Site.css b/Vidly/Content/Site.css index 6ea5d8f..9fbb2ba 100644 --- a/Vidly/Content/Site.css +++ b/Vidly/Content/Site.css @@ -1,5 +1,5 @@ body { - padding-top: 50px; + padding-top: 70px; padding-bottom: 20px; } diff --git a/Vidly/Controllers/CustomersController.cs b/Vidly/Controllers/CustomersController.cs new file mode 100644 index 0000000..b0617d1 --- /dev/null +++ b/Vidly/Controllers/CustomersController.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using Vidly.Models; +using Vidly.ViewModels; + +namespace Vidly.Controllers +{ + public class CustomersController : Controller + { + List customers = null; + + public CustomersController() + { + customers = new List + { + new Customer {Name="Nils Persson", Id=1}, + new Customer {Name="Pelle Rundström",Id=2}, + new Customer {Name="Ulla Ulriksson",Id=3} + }; + } + + // GET: Vidly + public ActionResult Index() + { + return View(); + } + + public ActionResult Customers() + { + + var viewModel = new CustomersViewModel() + { + Customers = customers + }; + + return View(viewModel); + } + + [Route("Customers/Details/{nr}")] + public ActionResult Customer(int nr) + { + foreach(var cust in customers) + { + if (cust.Id == nr) + { + return View(cust); + } + } + return View(new Customer { Name="",Id=0}); + } + + public ActionResult Movies() + { + return View(); + } + } +} \ No newline at end of file diff --git a/Vidly/Controllers/MoviesController.cs b/Vidly/Controllers/MoviesController.cs index a38a84c..74b16e1 100644 --- a/Vidly/Controllers/MoviesController.cs +++ b/Vidly/Controllers/MoviesController.cs @@ -10,6 +10,16 @@ namespace Vidly.Controllers { public class MoviesController : Controller { + List movies = null; + public MoviesController() + { + movies = new List + { + new Movie{Name="Never say never again", Id=1}, + new Movie{Name="Doctor Zivago",Id=2}, + new Movie{Name="Hånkentomtarna",Id=3} + }; + } // GET: Movies public ActionResult Random() { @@ -22,7 +32,8 @@ namespace Vidly.Controllers //var viewResult = new ViewResult(); //viewResult.ViewData.Model = movie; - var viewModel = new RandomMovieViewModel() { + var viewModel = new RandomMovieViewModel() + { Movie = movie, Customers = customers }; @@ -54,11 +65,22 @@ namespace Vidly.Controllers return Content($"pageIndex={pageIndex}&sortBy={sortBy}"); } + public ActionResult Movies() + { + var viewModel = new MoviesViewModel() + { + Movies = movies + }; + return View(viewModel); + } + [Route("movies/released/{year}/{month:regex(\\d{2}):range(1,12)}")] public ActionResult ByReleaseDate(int year, int month) { return Content(year + "/" + month); } + + } } \ No newline at end of file diff --git a/Vidly/Vidly.csproj b/Vidly/Vidly.csproj index e5b0104..e9c4d97 100644 --- a/Vidly/Vidly.csproj +++ b/Vidly/Vidly.csproj @@ -177,6 +177,7 @@ + Global.asax @@ -187,6 +188,8 @@ + + @@ -247,6 +250,10 @@ + + + + diff --git a/Vidly/ViewModels/CustomersViewModel.cs b/Vidly/ViewModels/CustomersViewModel.cs new file mode 100644 index 0000000..9b860c4 --- /dev/null +++ b/Vidly/ViewModels/CustomersViewModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Vidly.Models; + +namespace Vidly.ViewModels +{ + public class CustomersViewModel + { + public List Customers { get; set; } + } +} \ No newline at end of file diff --git a/Vidly/ViewModels/MoviesViewModel.cs b/Vidly/ViewModels/MoviesViewModel.cs new file mode 100644 index 0000000..c7949a0 --- /dev/null +++ b/Vidly/ViewModels/MoviesViewModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Vidly.Models; + +namespace Vidly.ViewModels +{ + public class MoviesViewModel + { + public List Movies { get; set; } + } +} \ No newline at end of file diff --git a/Vidly/Views/Customers/Customer.cshtml b/Vidly/Views/Customers/Customer.cshtml new file mode 100644 index 0000000..235d3ff --- /dev/null +++ b/Vidly/Views/Customers/Customer.cshtml @@ -0,0 +1,10 @@ +@model Vidly.Models.Customer +@{ + ViewBag.Title = "Customer"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

Customer

+ +

@Model.Name - @Model.Id

+ diff --git a/Vidly/Views/Customers/Customers.cshtml b/Vidly/Views/Customers/Customers.cshtml new file mode 100644 index 0000000..865759e --- /dev/null +++ b/Vidly/Views/Customers/Customers.cshtml @@ -0,0 +1,23 @@ +@model Vidly.ViewModels.CustomersViewModel +@{ + ViewBag.Title = "Customers"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

Customers

+ +@if (Model.Customers.Count == 0) +{ + No one has rented this movie before. +} +else +{ +
    + @foreach (var customer in Model.Customers) + { + @*
  • @customer.Name
  • *@ +
  • @Html.ActionLink(@customer.Name, "Details", "Customers", new { id = @customer.Id },null)
  • + } +
+ +} \ No newline at end of file diff --git a/Vidly/Views/Customers/Index.cshtml b/Vidly/Views/Customers/Index.cshtml new file mode 100644 index 0000000..43f7c7f --- /dev/null +++ b/Vidly/Views/Customers/Index.cshtml @@ -0,0 +1,11 @@ + +@{ + ViewBag.Title = "Vidly"; +} + +
+

V i d l y

+

Vidly is a great video rental system built in MVC5 with entity framework, Razorviews and Javascript.

+ @*

Learn more »

*@ +
+ diff --git a/Vidly/Views/Movies/Movies.cshtml b/Vidly/Views/Movies/Movies.cshtml new file mode 100644 index 0000000..fc23bf0 --- /dev/null +++ b/Vidly/Views/Movies/Movies.cshtml @@ -0,0 +1,23 @@ +@model Vidly.ViewModels.MoviesViewModel +@{ + ViewBag.Title = "Movies"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

Movies

+ +@if (Model.Movies.Count == 0) +{ + No one has rented this movie before. +} +else +{ +
    + @foreach (var movie in Model.Movies) + { +
  • @movie.Name
  • + @*
  • @Html.ActionLink(@customer.Name, "Details", "Customers", new { id = @customer.Id }, null)
  • *@ + } +
+ +} \ No newline at end of file diff --git a/Vidly/Views/Shared/_NavBar.cshtml b/Vidly/Views/Shared/_NavBar.cshtml index 6a149ed..70b22b3 100644 --- a/Vidly/Views/Shared/_NavBar.cshtml +++ b/Vidly/Views/Shared/_NavBar.cshtml @@ -4,13 +4,13 @@ - @Html.ActionLink("My Web Portal", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" }) + @Html.ActionLink("Vidly", "Index", "Customers", new { area = "" }, new { @class = "navbar-brand" })