private bool ActiveReservationsFound(Dictionary <string, string> errors, ReactCinemaDbContext context) { DateTime current = DateTime.Now; List <Reservation> reservations = context.Reservations .Where(r => r.Showtime.ShowtimeGroupEntry.ShowtimeGroup.ShowtimeGroupID == ShowtimeGroupID && current < r.Showtime.EndTime) .Include(r => r.Showtime) .ToList(); foreach (Reservation reservation in reservations) { DateTime reservationDate = reservation.Showtime.StartTime; if (reservationDate < FromDate || reservationDate > ToDate) { errors.Add("general", $"This update would remove active reservation {reservation.ReservationID}"); return(true); } foreach (ShowtimeGroupEntry entry in ShowtimeGroupEntries) { if (reservationDate.TimeOfDay == TimeSpan.Parse(entry.StartTime) && reservation.Showtime.ExperienceID == entry.ExperienceID && reservation.Showtime.RoomID == entry.RoomID) { return(false); } } errors.Add("general", $"This update would remove active reservation {reservation.ReservationID}"); return(true); } return(false); }
public void GenerateShowtimes(ReactCinemaDbContext context) { if (Movie == null) { Movie = context.Movies.Find(MovieID); } foreach (ShowtimeGroupEntry entry in ShowtimeGroupEntries) { entry.GenerateShowtimes(Movie, FromDate, ToDate); } }
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 bool CanBeDeleted(ReactCinemaDbContext context, Dictionary <string, string> errors) { DateTime current = DateTime.Now; Reservation reservation = context.Reservations .Where(r => r.Showtime.ShowtimeGroupEntry.ShowtimeGroup.ShowtimeGroupID == ShowtimeGroupID && current < r.Showtime.EndTime) .FirstOrDefault(); if (reservation != null) { errors.Add("general", $"Reservation {reservation.ReservationID} holds a showtime associated with this group."); return(false); } return(true); }
public bool CanBeDeleted(ReactCinemaDbContext context, Dictionary <string, string> errors) { DateTime current = DateTime.Now; Reservation reservation = context.Reservations .Where(r => r.Showtime.MovieID == MovieID && current < r.Showtime.EndTime) .FirstOrDefault(); if (reservation != null) { errors.Add("general", "Active reservations exist on this movie."); return(false); } return(true); }
public Dictionary <string, string> Validate(ReactCinemaDbContext context) { if (Movie == null) { Movie = context.Movies.Find(MovieID); } Dictionary <string, string> errors = new Dictionary <string, string>(); if (!ValidFields(errors) || OverlapFound(errors, context)) { return(errors); } if (ShowtimeGroupID != 0) { ActiveReservationsFound(errors, context); } return(errors); }
public RoomController(ReactCinemaDbContext context) { _context = context; }
public MovieController(ReactCinemaDbContext context) { _context = context; }
public ShowtimeController(ReactCinemaDbContext context) { _context = context; }
public ExperienceController(ReactCinemaDbContext context) { _context = context; }
public ReservationController(ReactCinemaDbContext context) { _context = context; }