// GET: Movies public ActionResult Index(int?id, string key) { int index = id ?? 1; var viewModel = new MoviesIndexViewModel(); int entriesPerPage = viewModel.NumberOfRows * viewModel.NumberOfColumns; int skip = (index - 1) * entriesPerPage; int count; if (string.IsNullOrEmpty(key)) { viewModel.Movies = moviesRepository.GetAllMovies().OrderBy(movie => movie.Name).Skip(skip).Take(entriesPerPage).ToList(); count = moviesRepository.GetCount(); } else { IEnumerable <Movie> selectedMoviesList = moviesRepository.GetAllMovies().Where(movie => movie.Name.ToUpper().Contains(key.ToUpper())); count = selectedMoviesList.Count(); viewModel.Movies = selectedMoviesList.OrderBy(movie => movie.Name).Skip(skip).Take(entriesPerPage).ToList(); } viewModel.PageNumber = index; viewModel.NumberOfPages = (int)Math.Ceiling((float)count / entriesPerPage); if (viewModel.NumberOfPages == 0) { viewModel.NumberOfPages = 1; } viewModel.key = key; return(View(viewModel)); }
VaryByParam = "Name;Min;Max")] //VaryByParam = "*", VaryByParam = "none" //1dk oyunca veriler burda duracak süre dolunca istek gelirse tekrar veritabanından alınacak public ActionResult List(MoviesIndexViewModel moviesIndexViewModel) { if (moviesIndexViewModel == null) { moviesIndexViewModel = new MoviesIndexViewModel(); } var movies = db.Movies.AsQueryable(); if (!string.IsNullOrWhiteSpace(moviesIndexViewModel.Name)) { movies = movies.Where(e => e.Name.Contains(moviesIndexViewModel.Name)); } if (!string.IsNullOrWhiteSpace(moviesIndexViewModel.YearId)) { movies = movies.Where(e => e.ProductionYear == moviesIndexViewModel.YearId); } if (!string.IsNullOrWhiteSpace(moviesIndexViewModel.Min) || !string.IsNullOrWhiteSpace(moviesIndexViewModel.Max)) { double min = 0; if (double.TryParse(moviesIndexViewModel.Min, out min)) { movies = movies.Where(e => e.BoxOfficeReturn >= min); } double max = 0; if (double.TryParse(moviesIndexViewModel.Max, out max)) { movies = movies.Where(e => e.BoxOfficeReturn >= max); } } moviesIndexViewModel.Movies = movies.ToList(); var years = new List <SelectListItem>(); for (int i = DateTime.Now.Year; i >= 1950; i--) { years.Add(new SelectListItem() { Value = i.ToString(), Text = i.ToString() }); } moviesIndexViewModel.Year = new SelectList(years, "Value", "Text", moviesIndexViewModel.YearId); return(View(moviesIndexViewModel)); }
public ActionResult Index(int id) { MoviesIndexViewModel viewModel = new MoviesIndexViewModel() { Movie = gm.Read(id) }; return(View(viewModel)); }
public ActionResult GetMoviesFromSession() { var model = new MoviesIndexViewModel() { Movies = GetList(false) }; return(View("Index", model)); }
public static MoviesIndexViewModel GetAllByCategory(DatabaseContext db, string category) { var viewModel = new MoviesIndexViewModel { Movies = MovieHelper.GetMovies(db.Movies, category), AvailableCategories = MovieHelper.GetCategories(db.Movies).ToList(), SelectedCategory = category }; return(viewModel); }
// GET: Movies //public ViewResult Index() // 1 public ViewResult Index(MoviesIndexViewModel moviesIndexViewModel) // 2 { // 1 ////var model = db.Movies.ToList(); //var model = GetList(); ////ViewBag.count = model.Count; //ViewData["count"] = model.Count; //return View(model); // 2 var years = new List <SelectListItem>(); //years.Add(new SelectListItem() //{ // Value = "", // Text = "-- All --" //}); for (int i = DateTime.Now.Year; i >= 1950; i--) { years.Add(new SelectListItem() { Value = i.ToString(), Text = i.ToString() }); } if (moviesIndexViewModel == null) { moviesIndexViewModel = new MoviesIndexViewModel(); } var query = db.Movies.AsQueryable(); if (!String.IsNullOrWhiteSpace(moviesIndexViewModel.YearId)) { query = query.Where(e => e.ProductionYear == moviesIndexViewModel.YearId); } if (!String.IsNullOrWhiteSpace(moviesIndexViewModel.Name)) { query = query.Where(e => e.Name.ToLower().Contains(moviesIndexViewModel.Name.ToLower().Trim())); } if (!String.IsNullOrWhiteSpace(moviesIndexViewModel.Min)) { double minimum = Convert.ToDouble(moviesIndexViewModel.Min.Trim().Replace(",", "."), CultureInfo.InvariantCulture); query = query.Where(e => e.BoxOfficeReturn >= minimum); } if (!String.IsNullOrWhiteSpace(moviesIndexViewModel.Max)) { double maximum = Convert.ToDouble(moviesIndexViewModel.Max.Trim().Replace(",", "."), CultureInfo.InvariantCulture); query = query.Where(e => e.BoxOfficeReturn <= maximum); } moviesIndexViewModel.Movies = query.ToList(); moviesIndexViewModel.Years = new SelectList(years, "Value", "Text", moviesIndexViewModel.YearId); return(View(moviesIndexViewModel)); }
// GET: Movies /// <summary> /// Moviesページトップ /// </summary> /// <param name="movieGenre">一覧のジャンル絞り込み条件</param> /// <param name="searchString">一覧のタイトル絞り込み条件</param> /// <returns></returns> public ActionResult Index(string movieGenre, string searchString) { // List<Movie>を返却する。 // return View(db.Movies.ToList()); // ラッパのMoviesIndexViewModelを用いる //var model = new MoviesIndexViewModel(db.Movies.ToList()); // Movie結果一覧に絞り込み条件を追加しラッパへ //var movies = from m in db.Movies // select m; //if (!String.IsNullOrEmpty(searchString)) { // movies = movies.Where(s => s.Title.Contains(searchString)); //} //var model = new MoviesIndexViewModel(movies.ToList()); // ジャンル一覧作成 var GenreLst = getGenreList(); // ViewBagに結果を格納 // ※View側の@Html.DropDownListではViewBagから検索する仕様 // ※GenreLstクエリとMoviesクエリのマルチタスクは? // → 単一のDbContextが複数のクエリをマルチタスクで扱う事ができないため // シングルタスクで実行 ViewBag.movieGenre = new SelectList(GenreLst); var movies = from m in db.Movies select m; #region Add SQL Filter // タイトルの絞り込み条件を追加 if (!String.IsNullOrEmpty(searchString)) { movies = movies.Where(s => s.Title.Contains(searchString)); } // ジャンルの絞り込み条件を追加 if (!string.IsNullOrEmpty(movieGenre)) { movies = movies.Where(x => x.Genre == movieGenre); } #endregion var moviedata = movies.ToList(); // Movie一覧からViewModelを作成 var model = new MoviesIndexViewModel(moviedata); return(View(model)); }
public ViewResult List(MoviesIndexViewModel moviesIndexViewModel) { if (moviesIndexViewModel == null) { moviesIndexViewModel = new MoviesIndexViewModel(); } var moviesQuery = db.Movies.AsQueryable(); moviesIndexViewModel.Movies = moviesQuery.ToList(); return(View(moviesIndexViewModel)); }
public IActionResult Movies(MoviesIndexViewModel model) { if (model.SearchText == null) { model.TotalPages = (int)Math.Ceiling(this.movieService.Total() / (double)pageSize); model.Movies = this.movieService.ListAllMovies(model.Page, pageSize); } else { model.TotalPages = (int)Math.Ceiling(this.movieService.TotalContainingText(model.SearchText) / (double)pageSize); model.Movies = this.movieService.ListByContainingText(model.SearchText, model.Page, pageSize); } return(View(model)); }
public async Task when_no_year_is_provided_then_the_full_list_of_movies_is_returned() { //Arrange var years = new List <int> { 2017, 2018 }; var movies = new List <MovieModel> { new MovieModel { Id = 1, Title = "Uno", Year = 2017 }, new MovieModel { Id = 2, Title = "Due", Year = 2018 } }; IMovieRepository repository = Substitute.For <IMovieRepository>(); repository.LoadAllYearsAsync().Returns(years); repository.LoadAllMoviesAsync().Returns(movies); IStarsCalculator starsCalculator = Substitute.For <IStarsCalculator>(); starsCalculator.GetStarsFromRatings(Arg.Any <List <RatingComponent> >()).Returns(3); MoviesController controller = new MoviesController(repository, starsCalculator); //Act IActionResult actualResult = await controller.Index(null); //Assert #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed repository.Received(1).LoadAllYearsAsync(); repository.Received(1).LoadAllMoviesAsync(); repository.DidNotReceive().LoadMoviesByYearAsync(Arg.Any <int>()); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed actualResult.Should().BeOfType <ViewResult>(); ViewResult viewResult = (ViewResult)actualResult; viewResult.ViewData.Model.Should().BeAssignableTo <MoviesIndexViewModel>(); MoviesIndexViewModel viewModel = (MoviesIndexViewModel)viewResult.ViewData.Model; viewModel.IsYear.Should().Be(false); viewModel.Years.Should().BeEquivalentTo(years); viewModel.Movies.Should().HaveCount(2); viewModel.Movies.First().Id.Should().Be(movies.First().Id); viewModel.Movies.First().Title.Should().Be(movies.First().Title); viewModel.Movies.First().Year.Should().Be(movies.First().Year); viewModel.Movies.First().Stars.Should().Be(3); viewModel.Movies.Last().Id.Should().Be(movies.Last().Id); viewModel.Movies.Last().Title.Should().Be(movies.Last().Title); viewModel.Movies.Last().Year.Should().Be(movies.Last().Year); viewModel.Movies.Last().Stars.Should().Be(3); }
// GET: Movies //public ViewResult Index() public ViewResult Index(MoviesIndexViewModel moviesIndexViewModel) { //var model = db.Movies.ToList(); var model = GetList(); //ViewData["count"] = model.Count; ViewBag.count = model.Count; var years = new List <SelectListItem>(); years.Add(new SelectListItem() { Value = "", Text = "---All---" }); for (int i = DateTime.Now.Year; i >= 1950; i--) { years.Add(new SelectListItem() { Value = i.ToString(), Text = i.ToString() }); } if (moviesIndexViewModel == null) { moviesIndexViewModel = new MoviesIndexViewModel(); } if (String.IsNullOrWhiteSpace(moviesIndexViewModel.YearId)) { moviesIndexViewModel.Movies = db.Movies.ToList(); } else { moviesIndexViewModel.Movies = db.Movies.Where(e => e.ProductionYear == moviesIndexViewModel.YearId).ToList(); } moviesIndexViewModel.Year = new SelectList(years, "Value", "Text", moviesIndexViewModel.YearId); //var moviesIndexViewModel = new MoviesIndexViewModel() //{ // Movies = model //}; //return View(model); return(View(moviesIndexViewModel)); }
// GET: Movies public ViewResult Index(MoviesIndexViewModel moviesIndexViewModel) //index aksiyonu verileri listelemek için kullanılır genelde { //var model = db.Movies.ToList(); var model = GetList(); ViewData["count"] = model.Count; var years = new List <SelectListItem>(); years.Add(new SelectListItem() { Value = "", Text = "--All--" }); for (int i = DateTime.Now.Year; i > 1950; i--) { years.Add(new SelectListItem() { Value = i.ToString(), Text = i.ToString() }); } if (moviesIndexViewModel == null) { moviesIndexViewModel = new MoviesIndexViewModel(); } if (String.IsNullOrWhiteSpace(moviesIndexViewModel.YearId)) { moviesIndexViewModel.movies = db.Movies.ToList(); } else { moviesIndexViewModel.movies = db.Movies.Where(e => e.ProductionYear == moviesIndexViewModel.YearId).ToList(); } //moviesIndexViewModel.movies = db.Movies.ToList(); moviesIndexViewModel.Years = new SelectList(years, "Value", "Text", moviesIndexViewModel.YearId); //return View(model); //veri taşıyacaksak bunu view içinde yapmalıyız return(View(moviesIndexViewModel)); }
// movies/Index public ActionResult Index(int?pageIndex, string sortby) { if (!pageIndex.HasValue) { pageIndex = 1; } if (String.IsNullOrWhiteSpace(sortby)) { sortby = "Name"; } // return Content(String.Format("first {0} and second {1}", pageIndex, sortby)); var viewModel = new MoviesIndexViewModel { Movies = _context.Movies.Include(m => m.Genre).ToList() }; return(View(viewModel)); }
// GET: Movies public ViewResult Index(MoviesIndexViewModel moviesIndexViewModel) { if (moviesIndexViewModel == null || string.IsNullOrWhiteSpace(moviesIndexViewModel.YearId)) { moviesIndexViewModel = new MoviesIndexViewModel(); moviesIndexViewModel.Movies = GetList(); } else { moviesIndexViewModel.Movies = db.Movies.Where(e => e.ProductionYear.Equals(moviesIndexViewModel.YearId)).ToList(); } var qr = db.Movies.AsQueryable(); qr = qr.Where(a => a.ProductionYear.Equals("")); var years = new List <SelectListItem>(); //for (int i = DateTime.Now.Year; i >= 1950; i--) // years.Add(new SelectListItem() // { // Text = i.ToString(), // Value = i.ToString() // }); years = db.Movies.GroupBy(e => e.ProductionYear).Select(m => new SelectListItem() { Text = m.Key, Value = m.Key }).ToList(); years.Insert(0, new SelectListItem() { Text = @"--All--", Value = "" }); moviesIndexViewModel.Years = new SelectList(years, "Value", "Text", moviesIndexViewModel.YearId); ViewData["count"] = moviesIndexViewModel.Movies.Count; return(View(moviesIndexViewModel)); }
// GET: Movies public ActionResult Index() { ViewBag.TableTitle = "Filmlərin siyahısı"; ViewData["tema1"] = "esgerin sohbeti"; ViewData["tema2"] = "esgerin sohbeti 2"; P112CinemaEntities _context = new P112CinemaEntities(); Student student = new Student() { Name = "Ceyhun", Lastname = "Cavadov" }; List <Movy> movies = _context.Movies.ToList(); MoviesIndexViewModel model = new MoviesIndexViewModel(); model.Student = student; model.Movies = movies; return(View(model)); }
[OutputCache(Duration = 60, Location = OutputCacheLocation.ServerAndClient, NoStore = true, VaryByParam = "*")] // VaryByParam = "Name;Min;Max" , VaryByParam = "none" public ActionResult List(MoviesIndexViewModel moviesIndexViewModel) // son yaptığımız 16:00-17:00 (Hüseyin) { if (moviesIndexViewModel == null) { moviesIndexViewModel = new MoviesIndexViewModel(); } var movies = db.Movies.AsQueryable(); if (!string.IsNullOrWhiteSpace(moviesIndexViewModel.Name)) { movies = movies.Where(e => e.Name.Contains(moviesIndexViewModel.Name)); } if (!string.IsNullOrWhiteSpace(moviesIndexViewModel.YearId)) { movies = movies.Where(e => e.ProductionYear == moviesIndexViewModel.YearId); } //if(!string.IsNullOrWhiteSpace(moviesIndexViewModel.Min) && !string.IsNullOrWhiteSpace(moviesIndexViewModel.Max)) //{ // double minValue = 0; // double maxValue = Convert.ToDouble(moviesIndexViewModel.Max); // if (double.TryParse(moviesIndexViewModel.Min,out minValue)) // { // movies = movies.Where(e => e.BoxOfficeReturn >= minValue & e.BoxOfficeReturn <= maxValue); // } //} if (!string.IsNullOrWhiteSpace(moviesIndexViewModel.Min)) { double minValue = 0; if (double.TryParse(moviesIndexViewModel.Min, out minValue)) { movies = movies.Where(e => e.BoxOfficeReturn <= minValue); } } if (!string.IsNullOrWhiteSpace(moviesIndexViewModel.Max)) { double maxValue = 0; if (double.TryParse(moviesIndexViewModel.Max, out maxValue)) { movies = movies.Where(e => e.BoxOfficeReturn <= maxValue); } } moviesIndexViewModel.Movies = movies.ToList(); var years = new List <SelectListItem>(); for (int i = DateTime.Now.Year; i >= 1960; i--) { years.Add(new SelectListItem() { Value = i.ToString(), Text = i.ToString() }); } moviesIndexViewModel.Years = new SelectList(years, "Value", "Text", moviesIndexViewModel.YearId); return(View(moviesIndexViewModel)); }