Movies included in database as well and handled in site
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Data.Entity;
|
||||
using System.Web.Mvc;
|
||||
using Vidly.Models;
|
||||
using Vidly.ViewModels;
|
||||
@ -10,70 +11,83 @@ namespace Vidly.Controllers
|
||||
{
|
||||
public class MoviesController : Controller
|
||||
{
|
||||
List<Movie> movies = null;
|
||||
//List<Movie> movies = null;
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
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}
|
||||
};
|
||||
_context = new ApplicationDbContext();
|
||||
//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()
|
||||
{
|
||||
var movie = new Movie() { Name = "Shrek!" };
|
||||
var customers = new List<Customer>
|
||||
{
|
||||
new Customer {Name="Customer 1"},
|
||||
new Customer {Name="Customer 2"}
|
||||
};
|
||||
//var viewResult = new ViewResult();
|
||||
//viewResult.ViewData.Model = movie;
|
||||
//// GET: Movies
|
||||
//public ActionResult Random()
|
||||
//{
|
||||
// var movie = new Movie() { Name = "Shrek!" };
|
||||
// var customers = new List<Customer>
|
||||
// {
|
||||
// new Customer {Name="Customer 1"},
|
||||
// new Customer {Name="Customer 2"}
|
||||
// };
|
||||
// //var viewResult = new ViewResult();
|
||||
// //viewResult.ViewData.Model = movie;
|
||||
|
||||
var viewModel = new RandomMovieViewModel()
|
||||
{
|
||||
Movie = movie,
|
||||
Customers = customers
|
||||
};
|
||||
// var viewModel = new RandomMovieViewModel()
|
||||
// {
|
||||
// Movie = movie,
|
||||
// Customers = customers
|
||||
// };
|
||||
|
||||
return View(viewModel);
|
||||
// return View(viewModel);
|
||||
|
||||
//return View(movie);
|
||||
//return Content("Hello World");
|
||||
//return HttpNotFound();
|
||||
//return new EmptyResult();
|
||||
//return RedirectToAction("Index", "Home",new { page = 1, sortBy = "name" });
|
||||
// //return View(movie);
|
||||
// //return Content("Hello World");
|
||||
// //return HttpNotFound();
|
||||
// //return new EmptyResult();
|
||||
// //return RedirectToAction("Index", "Home",new { page = 1, sortBy = "name" });
|
||||
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
public ActionResult Edit(int id)
|
||||
{
|
||||
return Content("id=" + id);
|
||||
}
|
||||
//public ActionResult Edit(int id)
|
||||
//{
|
||||
// return Content("id=" + id);
|
||||
//}
|
||||
|
||||
public ActionResult Index(int? pageIndex, string sortBy)
|
||||
{
|
||||
if (!pageIndex.HasValue)
|
||||
pageIndex = 1;
|
||||
//public ActionResult Index(int? pageIndex, string sortBy)
|
||||
//{
|
||||
// if (!pageIndex.HasValue)
|
||||
// pageIndex = 1;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(sortBy))
|
||||
sortBy = "Name";
|
||||
// if (string.IsNullOrWhiteSpace(sortBy))
|
||||
// sortBy = "Name";
|
||||
|
||||
return Content($"pageIndex={pageIndex}&sortBy={sortBy}");
|
||||
}
|
||||
// return Content($"pageIndex={pageIndex}&sortBy={sortBy}");
|
||||
//}
|
||||
|
||||
public ActionResult Movies()
|
||||
{
|
||||
var viewModel = new MoviesViewModel()
|
||||
{
|
||||
Movies = movies
|
||||
Movies = _context.Movies.Include(m => m.MovieGenre).ToList()
|
||||
};
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[Route("Movies/Movies/{nr}")]
|
||||
public ActionResult Movie(int nr)
|
||||
{
|
||||
var movie = _context.Movies.Include(c => c.MovieGenre).SingleOrDefault(c => c.Id == nr);
|
||||
if (movie == null)
|
||||
return HttpNotFound();
|
||||
return View(movie);
|
||||
}
|
||||
|
||||
|
||||
[Route("movies/released/{year}/{month:regex(\\d{2}):range(1,12)}")]
|
||||
public ActionResult ByReleaseDate(int year, int month)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user