public IActionResult FindProjection(int?movieId) { var viewModel = new FindProjectionInputModel(); IEnumerable <MovieDropdownModel> movies; IEnumerable <CinemaDropdownModel> cinemas; if (movieId == null) { movies = this.moviesService.AllMovies <MovieDropdownModel>() .Where(x => x.ReleaseDate.DayOfYear < DateTime.UtcNow.DayOfYear); cinemas = this.cinemaService.AllCinemas <CinemaDropdownModel>(); } else { var movie = this.moviesService.MovieExist(movieId.Value); if (movie == false) { movies = this.moviesService.AllMovies <MovieDropdownModel>() .Where(x => x.ReleaseDate.DayOfYear < DateTime.UtcNow.DayOfYear); cinemas = this.cinemaService.AllCinemas <CinemaDropdownModel>(); } else { movies = this.moviesService.AllMovies <MovieDropdownModel>() .Where(x => x.Id == movieId); cinemas = this.cinemaService.AllCinemas <CinemaDropdownModel>(); } } viewModel.Cinemas = cinemas; viewModel.Movies = movies; return(this.View(viewModel)); }
public IActionResult FoundProjectionsResult(int cinemaId, int?movieId, DateTime?starttime) { var projectionsList = new List <ProjectionViewModel>(); var viewModel = new AllProjectionsViewModel(); int movieIdToFind = 0; DateTime toFind = DateTime.UtcNow; if (starttime.HasValue) { DateTime haveDate = starttime.Value; if (haveDate.DayOfYear < toFind.DayOfYear) { this.ModelState.AddModelError(string.Empty, ErrorBeforeToday); var movies = this.moviesService.AllMovies <MovieDropdownModel>(); var cinemas = this.cinemaService.AllCinemas <CinemaDropdownModel>(); var inputViewModel = new FindProjectionInputModel { Cinemas = cinemas, Movies = movies, }; return(this.RedirectToAction("FindProjection", inputViewModel)); } } if (starttime == null && movieId != null) { movieIdToFind = movieId ?? default; projectionsList = this.projectionsService .ProjectionByMovieIdAndCinemaIdOnly <ProjectionViewModel>(movieIdToFind, cinemaId) .ToList(); viewModel.AllProjections = projectionsList; return(this.View(viewModel)); } else { toFind = starttime ?? DateTime.UtcNow; } if (movieId == null) { if (toFind.DayOfYear == DateTime.UtcNow.DayOfYear) { projectionsList = this.projectionsService .ProjectionByCinemaIdAndDate <ProjectionViewModel>(cinemaId, toFind) .Where(x => x.StartTime.Hour > DateTime.UtcNow.AddHours(3).Hour) .ToList(); } else { projectionsList = this.projectionsService .ProjectionByCinemaIdAndDate <ProjectionViewModel>(cinemaId, toFind) .ToList(); } } else { if (toFind.DayOfYear == DateTime.UtcNow.DayOfYear) { projectionsList = this.projectionsService .ProjectionByMovieIdAdCinemaId <ProjectionViewModel>((int)movieId, cinemaId, toFind) .Where(x => x.StartTime.Hour > DateTime.UtcNow.AddHours(3).Hour) .ToList(); } else { projectionsList = this.projectionsService .ProjectionByMovieIdAdCinemaId <ProjectionViewModel>((int)movieId, cinemaId, toFind) .ToList(); } } viewModel.AllProjections = projectionsList; if (viewModel == null) { return(this.NotFound()); } return(this.View(viewModel)); }