public ActionResult Index() { if (HttpContext.Session.GetObject <Account>("User") != null) { MovieIndexViewModel viewModel = new MovieIndexViewModel { Account = HttpContext.Session.GetObject <Account>("User"), Movies = _context.GetMovies() }; return(View(viewModel)); } else { return(View("NotLoggedIn")); } }
/// <summary> /// This controller action returns a view which shows you all the movies. /// </summary> public async Task <ActionResult> Index(string message) { if (Session["LoggedIn"] == null || Session["LoggedIn"].Equals(false)) { return(RedirectToRoute(new { controller = "Home", action = "Index" })); } ViewBag.Message = message; var movies = await _moviesLogic.GetMovies(false); var mappedMovies = ModelMapper.MapFromListOfMovieBllModelToListOfMovieViewModelList(movies); var moviesListWrapperObject = new MoviesListWrapperViewModel() { Movies = mappedMovies, SearchText = "" }; return(View(moviesListWrapperObject)); }
public void GetMoviesTest() { //Arrange var seedDB = new List <MovieModelDAL>(); var seed = new MovieModelDAL { ID = 5050, Title = "Movie", Year = 2018, Rated = "10", Runtime = "20 min", Genre = "Commedy", Director = "Director", Plot = "Some Plot", Poster = "www.poster.com", ImdbRating = 10f, ScreenShot = "www.screenshot.com" }; seedDB.Add(seed); var controller = new MoviesLogic(new MovieDALStub(seedDB)); //Act var result1 = controller.GetMovies(true); //Assert Assert.IsTrue(result1.Result.Count == 1); }
public async Task <ActionResult> Index() { var allMovies = await _moviesLogic.GetMovies(true); if (Session["LoggedIn"] == null) { Session["LoggedIn"] = false; } else { ViewBag.LoggedIn = (bool)Session["LoggedIn"]; } var movies = new List <Movie>(); foreach (var movie in allMovies) { var newMovie = new Movie() { ID = movie.ID, Title = movie.Title, Year = movie.Year, Rated = movie.Rated, Runtime = movie.Runtime, Genre = movie.Genre, Director = movie.Director, Plot = movie.Plot, Poster = movie.Poster, ImdbRating = movie.ImdbRating, ScreenShot = movie.ScreenShot }; movies.Add(newMovie); } ; return(View(movies)); }
public ActionResult SubmitRating(int Rating, int MovieId) { string Message; if (Rating >= 0 && Rating <= 100) { Account account = HttpContext.Session.GetObject <Account>("User"); Message = _ratinglogic.SubmitRating(Rating, MovieId, account); } else { Message = "Please insert a rating between 0 and 100"; } MovieIndexViewModel viewModel = new MovieIndexViewModel { Account = HttpContext.Session.GetObject <Account>("User"), Movies = _movielogic.GetMovies() }; viewModel.Message = Message; return(View("Views/Movies/Index.cshtml", viewModel)); }