Min lösning på övningen

This commit is contained in:
2019-01-17 23:11:33 +01:00
parent b6bf2776a8
commit cd91acdf53
12 changed files with 189 additions and 7 deletions

View File

@ -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<Customer> customers = null;
public CustomersController()
{
customers = new List<Customer>
{
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();
}
}
}

View File

@ -10,6 +10,16 @@ namespace Vidly.Controllers
{
public class MoviesController : Controller
{
List<Movie> movies = null;
public MoviesController()
{
movies = new List<Movie>
{
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);
}
}
}