public ActionResult PilotReview(int memberId) { PilotReviewViewModel viewModel = new PilotReviewViewModel(); Member member = _dataService.GetMemberWithPilotData(memberId); viewModel = InitializePilotReviewViewModel(member); if (User.IsInRole(UserRoles.Admin.ToString())) { viewModel.CanEditStageChecks = true; } else { int instructorId = ProfileCommon.GetProfile().MemberId; viewModel.CanEditStageChecks = _dataService.IsDesignatedForStageChecks(instructorId); } return(View(ViewNames.PilotReview, viewModel)); }
private bool ValidateReservation(ReservationViewModel model) { if (!_dataService.IsValidReservationDateRange(model.Id, model.AircraftId, model.StartDate.Date.Add(TimeSpan.Parse(model.StartTime)), model.EndDate.Date.Add(TimeSpan.Parse(model.EndTime)))) { ModelState.AddModelError(string.Empty, "A reservation already exists for this time period."); } // require provide instructor for non-checked out aircraft if ((model.InstructorId == null || model.InstructorId == 0)) { // exclude instructors and this aircraft owners if (!(User.IsInRole(UserRoles.Instructor.ToString()) | _dataService.IsAircraftOwner(model.MemberId, model.AircraftId))) { Member member = _dataService.GetMemberWithPilotData(model.MemberId); if (member.Checkouts.FirstOrDefault(c => c.AircraftId == model.AircraftId) == null) { ModelState.AddModelError(String.Empty, "Records indicate you are not checked out in this airplane.\nPlease add club instructor to your reservation or use different airplane."); } } } List <Reservation> existingReservations = _dataService.GetReservationListByMember(model.MemberId); DateTime today = DateTime.Now; // do not allow more than one reservation more than 10 days ahead if (model.StartDate >= today.AddDays(10)) { // find all other with start date more than 10 days Reservation advanceReservation = existingReservations.FirstOrDefault(r => (r.StartDate >= today.AddDays(10)) && r.Id != model.Id); if (advanceReservation != null) { ModelState.AddModelError(string.Empty, String.Format("One reservation already exists for time period 10 or more days ahead (start date {0}).\nYou are only allowed to have one reservation more than 10 days in advance", advanceReservation.StartDate.ToString("yyyy-MM-dd hh:mm"))); } } // check if there are any other aircraft reservations for the same period (excluding current one if updating) DateTime newReservationStart = model.StartDate.Add(TimeSpan.Parse(model.StartTime)); DateTime newReservationEnd = model.EndDate.Add(TimeSpan.Parse(model.EndTime)); Reservation overlapReservation = existingReservations.FirstOrDefault(r => r.Id != model.Id && ( (r.StartDate <= newReservationStart && r.EndDate > newReservationStart) || (r.StartDate < newReservationEnd && r.EndDate >= newReservationEnd) || (r.StartDate >= newReservationStart && r.EndDate <= newReservationEnd) )); if (overlapReservation != null) { Aircraft ac = _dataService.GetAircraftById(overlapReservation.AircraftId); ModelState.AddModelError(String.Empty, String.Format("Reservation conflicts with another reservation for {0} which starts at {1} and ends at {2}.\nPlease adjust your reservation times so there's no overlap.", ac.RegistrationNumber, overlapReservation.StartDate.ToString("yyyy-MM-dd hh:mm"), overlapReservation.EndDate.ToString("yyyy-MM-dd hh:mm"))); } return(ModelState.IsValid); }