public async Task <ActionResult> CinemaDetails(int?cinemaId) { if (cinemaId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Cinema cinema = await db.Cinemas.FindAsync(art => art.Id == cinemaId); if (cinema == null) { return(HttpNotFound()); } CinemaSeances cs = new CinemaSeances(); IEnumerable <Seance> seances_in_cinema = await db.Seances.FindAllAsync(seance => seance.Hall.CinemaId == cinema.Id); IEnumerable <DateTime> seances_dates = seances_in_cinema.Select(s => s.Date).Distinct().OrderBy(d => d.Date); foreach (var date in seances_dates) { DateSeances ds = new DateSeances(); ds.Date = date; ds.Seances = seances_in_cinema.Where(s => s.Date == date).OrderBy(s => s.MovieId).ToList <Seance>(); //from seance in movie_seances //where s cs.DateSeances.Add(ds); } cs.Cinema = cinema; return(View(cs)); }
public async Task<ActionResult> CinemaDetails(int? cinemaId) { if (cinemaId == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Cinema cinema = await db.Cinemas.FindAsync(art => art.Id == cinemaId); if (cinema == null) { return HttpNotFound(); } CinemaSeances cs = new CinemaSeances(); IEnumerable<Seance> seances_in_cinema = await db.Seances.FindAllAsync(seance => seance.Hall.CinemaId == cinema.Id ); IEnumerable<DateTime> seances_dates = seances_in_cinema.Select(s => s.Date).Distinct().OrderBy(d => d.Date); foreach (var date in seances_dates) { DateSeances ds = new DateSeances(); ds.Date = date; ds.Seances = seances_in_cinema.Where(s => s.Date == date).OrderBy(s => s.MovieId).ToList<Seance>(); //from seance in movie_seances //where s cs.DateSeances.Add(ds); } cs.Cinema = cinema; return View(cs); }
public async Task <ActionResult> MovieDetails(int?movieId) { if (movieId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Movie movie = await db.Movies.FindAsync(art => art.Id == movieId); if (movie == null) { return(HttpNotFound()); } //Move following code in corresponding Model MovieSeances ms = new MovieSeances(); ms.Movie = movie; ICollection <Cinema> cinemas = await db.Cinemas.GetAllAsync(); foreach (Cinema cinema in cinemas) { IEnumerable <Seance> seances_in_cinema = await db.Seances.FindAllAsync(seance => seance.Hall.CinemaId == cinema.Id); List <Seance> movie_seances = seances_in_cinema.Where(s => s.MovieId == movie.Id).OrderBy(s => s.Date).ToList <Seance>(); IEnumerable <DateTime> seances_dates = movie_seances.Select(s => s.Date).Distinct().OrderBy(d => d.Date); CinemaSeances cs = new CinemaSeances(); foreach (var date in seances_dates) { DateSeances ds = new DateSeances(); ds.Date = date; ds.Seances = movie_seances.Where(s => s.Date == date).ToList <Seance>(); //from seance in movie_seances //where s cs.DateSeances.Add(ds); } //cs.CinemaName = cinema.Name; cs.Cinema = cinema; ms.Cinemas.Add(cs); } return(View(ms)); }
public async Task<ActionResult> MovieDetails(int? movieId) { if (movieId == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Movie movie = await db.Movies.FindAsync(art => art.Id == movieId); if (movie == null) { return HttpNotFound(); } //Move following code in corresponding Model MovieSeances ms = new MovieSeances(); ms.Movie = movie; ICollection<Cinema> cinemas = await db.Cinemas.GetAllAsync(); foreach(Cinema cinema in cinemas) { IEnumerable<Seance> seances_in_cinema = await db.Seances.FindAllAsync(seance => seance.Hall.CinemaId == cinema.Id ); List<Seance> movie_seances = seances_in_cinema.Where(s => s.MovieId == movie.Id).OrderBy(s => s.Date).ToList<Seance>(); IEnumerable<DateTime> seances_dates = movie_seances.Select(s => s.Date).Distinct().OrderBy(d => d.Date ); CinemaSeances cs = new CinemaSeances(); foreach (var date in seances_dates) { DateSeances ds = new DateSeances(); ds.Date = date; ds.Seances = movie_seances.Where(s => s.Date == date).ToList<Seance>(); //from seance in movie_seances //where s cs.DateSeances.Add(ds); } //cs.CinemaName = cinema.Name; cs.Cinema = cinema; ms.Cinemas.Add(cs); } return View(ms); }