public ActionResult GetProjectionsSort(string cinema, string SortProjections) { int cinemaID; if (cinema == null) { cinemaID = 0; } else { cinemaID = int.Parse(cinema); } List <Projection> Projections = new List <Projection>(); ProjectionVM projectionVM = new ProjectionVM(); if (SortProjections == "Name") { projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID).OrderBy(x => x.Movie.MovieName).ToList(); getMovies(projectionVM); projectionVM.Projections = projectionVM.Projections.Where(x => x.DateTimeStart > DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).GroupBy(x => x.MovieID).Select(g => g.First()).Take(16).ToList(); return(PartialView("GetProjections", projectionVM)); } else if (SortProjections == "Release") { projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID).OrderBy(x => x.Movie.ReleaseYear).ToList(); getMovies(projectionVM); projectionVM.Projections = projectionVM.Projections.Where(x => x.DateTimeStart > DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).GroupBy(x => x.MovieID).Select(g => g.First()).Take(16).ToList(); return(PartialView("GetProjections", projectionVM)); } else if (SortProjections == "Duration") { projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID).OrderBy(x => x.Movie.DurationInMinutes).ToList(); getMovies(projectionVM); projectionVM.Projections = projectionVM.Projections.Where(x => x.DateTimeStart > DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).GroupBy(x => x.MovieID).Select(g => g.First()).Take(16).ToList(); return(PartialView("GetProjections", projectionVM)); } projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID).ToList(); getMovies(projectionVM); projectionVM.Projections = projectionVM.Projections.Where(x => x.DateTimeStart > DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).GroupBy(x => x.MovieID).Select(g => g.First()).Take(16).ToList(); return(PartialView("GetProjections", projectionVM)); }
public void getMovies(ProjectionVM projectionVM) { foreach (Projection p in projectionVM.Projections) { if (!projectionVM.d.ContainsKey(p.MovieID)) { projectionVM.d[p.MovieID] = new List <string[]>(); } projectionVM.d[p.MovieID].Add(new string[] { p.TechnologyType.Name, p.DateTimeStart.DayOfWeek.ToString(), p.DateTimeStart.Hour.ToString(), Nule(p.DateTimeStart.Minute.ToString()), p.DateTimeStart.Year.ToString(), p.DateTimeStart.Month.ToString(), p.DateTimeStart.Day.ToString() }); } }
public ActionResult GetProjections(string cinema, string SortProjections, string search = "") { int cinemaID; if (cinema == null) { cinemaID = 0; } else { cinemaID = int.Parse(cinema); } List <Projection> Projections = new List <Projection>(); ProjectionVM projectionVM = new ProjectionVM(); if (SortProjections == "Name") { projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID).OrderBy(x => x.Movie.MovieName).ToList(); getMovies(projectionVM); projectionVM.Projections = projectionVM.Projections.Where(x => x.DateTimeStart > DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).GroupBy(x => x.MovieID).Select(g => g.First()).Take(16).ToList(); return(PartialView("GetProjections", projectionVM)); } else if (SortProjections == "Release") { projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID).OrderBy(x => x.Movie.ReleaseYear).ToList(); getMovies(projectionVM); projectionVM.Projections = projectionVM.Projections.Where(x => x.DateTimeStart > DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).GroupBy(x => x.MovieID).Select(g => g.First()).Take(16).ToList(); return(PartialView("GetProjections", projectionVM)); } else if (SortProjections == "Duration") { projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID).OrderBy(x => x.Movie.DurationInMinutes).ToList(); getMovies(projectionVM); projectionVM.Projections = projectionVM.Projections.Where(x => x.DateTimeStart > DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).GroupBy(x => x.MovieID).Select(g => g.First()).Take(16).ToList(); return(PartialView("GetProjections", projectionVM)); } if (cinemaID == 0) { return(PartialView("GetProjections", projectionVM)); } if (search == "") // vrati sve preko cinemaID { projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID).ToList(); getMovies(projectionVM); projectionVM.Projections = projectionVM.Projections.Where(x => x.DateTimeStart > DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).GroupBy(x => x.MovieID).Select(g => g.First()).Take(16).ToList(); } else // vrati klasicni contains { projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID && i.Movie.MovieName.Contains(search)).ToList(); getMovies(projectionVM); projectionVM.Projections = projectionVM.Projections.Where(x => x.DateTimeStart > DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).GroupBy(x => x.MovieID).Select(g => g.First()).Take(16).ToList(); if (projectionVM.Projections.Count() == 0) // pozovi algoritam { projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID).ToList(); getMovies(projectionVM); //da ne ponavlja filmove na naslovnoj stranici (postavi novi termin u projekciju) projectionVM.Projections = projectionVM.Projections.Where(x => x.DateTimeStart > DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).GroupBy(x => x.MovieID).Select(g => g.First()).Take(16).ToList(); List <string> lista = new List <string>(); foreach (Projection s in projectionVM.Projections) { lista.Add(s.Movie.MovieName.Trim() + '\n' + s.Movie.Synopsis.Trim()); } string bestMatch = lista.ContextFind(search).Split('\n')[0]; projectionVM.Projections.Clear(); projectionVM.Projections.Add(context.Projections.Where (i => i.CinemaHall.CinemaID == cinemaID && i.Movie.MovieName.Contains(bestMatch)).First()); projectionVM.didUMean = true; } } //projectionVM.Projections = context.Projections.Where(i => i.CinemaHall.CinemaID == cinemaID && i.Movie.MovieName.Contains(search)).ToList(); return(PartialView("GetProjections", projectionVM)); }