private PilotReviewViewModel InitializePilotReviewViewModel(Member member) { PilotReviewViewModel pilotVM = new PilotReviewViewModel() { MemberId = member.Id, PilotName = member.FullName, AircraftCheckouts = new List<AircraftCheckoutViewModel>() }; pilotVM.FlightReview = new FlightReviewViewModel(); if (member.FlightReviews != null && member.FlightReviews.Count > 0) { FlightReview review = member.FlightReviews.OrderByDescending(r => r.Date).First(); pilotVM.FlightReview.ReviewDate = review.Date;//ToString("MMMM dd, yyyy"); pilotVM.FlightReview.InstructorName = review.InstructorName; pilotVM.FlightReview.Notes = review.InstructorNotes; pilotVM.FlightReview.RetractTime = review.RetractTime; pilotVM.FlightReview.TotalTime = review.TotalTime; pilotVM.FlightReview.ReviewType = review.ReviewType; //pilotVM.FlightReview.I = member.FlightReviews.First().Id; } foreach (var pilotCheckout in member.Checkouts) { AircraftCheckoutViewModel checkoutVM = new AircraftCheckoutViewModel(); checkoutVM.Id = pilotCheckout.Id; checkoutVM.AircraftId = pilotCheckout.AircraftId; Aircraft aircraft = _dataService.GetAircraftById(pilotCheckout.AircraftId); checkoutVM.RegistrationNumber = aircraft.RegistrationNumber; checkoutVM.CheckoutDate = pilotCheckout.CheckoutDate; checkoutVM.InstructorId = pilotCheckout.InstructorId; var instructor = _dataService.GetMember(pilotCheckout.InstructorId); checkoutVM.InstructorName = instructor.FullName; pilotVM.AircraftCheckouts.Add(checkoutVM); } if(member.StageChecks != null) pilotVM.StageChecks = member.StageChecks.OrderBy(s => s.Date).ToList(); return pilotVM; }
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); }