private bool OverlapFound(Dictionary <string, string> errors, ReactCinemaDbContext context) { ShowtimeGroup overlappedGroup = context.ShowtimeGroups .Where(s => s.FromDate <ToDate && s.ToDate> FromDate && s.MovieID == MovieID && s.ShowtimeGroupID != ShowtimeGroupID) .FirstOrDefault(); if (overlappedGroup != null) { errors.Add("general", "Another Showtime Group was found which overlaps with this one."); return(true); } List <ShowtimeGroupEntry> orderedEntries = ShowtimeGroupEntries.OrderBy(e => e.RoomID).ThenBy(e => e.StartTime).ToList(); for (int i = 0; i < orderedEntries.Count; i++) { if (i == orderedEntries.Count - 1) { break; } else if (orderedEntries[i].Conflicts(orderedEntries[i + 1], Movie.Duration)) { errors.Add("general", $"Showtime {orderedEntries[i].FormatStartTime} overlaps with {orderedEntries[i+1].FormatStartTime}."); return(true); } } foreach (ShowtimeGroupEntry entry in ShowtimeGroupEntries) { entry.SetInterval(); for (DateTime date = FromDate; date <= ToDate; date = date.AddDays(1)) { DateTime showtimeDate = date.Date + entry.Interval; Showtime showtime = context.Showtimes .Where(s => s.RoomID == entry.RoomID && s.StartTime <showtimeDate.AddMinutes(Movie.Duration) && s.EndTime> showtimeDate && s.MovieID != MovieID) .Include(s => s.Movie) .FirstOrDefault(); if (showtime != null) { errors.Add("general", $"Showtime conflict with {showtime.Movie.Title} at {showtime.StartTime}"); return(true); } } } return(false); }
public bool CanBeDeleted(ReactCinemaDbContext context, Dictionary <string, string> errors) { Showtime showtime = context.Showtimes .Where(s => s.ExperienceID == ExperienceID) .FirstOrDefault(); if (showtime != null) { errors.Add("general", "The showtimes using this experience need to be removed first."); return(false); } return(true); }
public void GenerateShowtimes(Movie movie, DateTime fromDate, DateTime toDate) { SetInterval(); if (Showtimes == null) { Showtimes = new List <Showtime>(); } for (DateTime date = fromDate; date <= toDate; date = date.AddDays(1)) { DateTime showtimeDate = date.Date + Interval; Showtime newShowtime = new Showtime() { MovieID = movie.MovieID, StartTime = showtimeDate, EndTime = showtimeDate.AddMinutes(movie.Duration), RoomID = RoomID, Soldout = false, ExperienceID = ExperienceID }; Showtimes.Add(newShowtime); } }