public int AddFlightReview(FlightReview flightReview)
        {
            _repository.Add <FlightReview>(flightReview);
            _repository.UnitOfWork.SaveChanges();

            return(flightReview.Id);
        }
        public ActionResult UpdateFlightReview(int pilotId)
        {
            FlightReviewViewModel viewModel = new FlightReviewViewModel();

            viewModel.PilotId = pilotId;
            ProfileCommon profile = ProfileCommon.GetProfile();

            Member member = _dataService.GetMemberWithPilotData(pilotId);

            viewModel.PilotId   = pilotId;
            viewModel.PilotName = member.FullName;

            viewModel.InstructorId   = profile.MemberId;
            viewModel.InstructorName = profile.FirstName + " " + profile.LastName;

            if (member.FlightReviews != null && member.FlightReviews.Count() > 0)
            {
                FlightReview lastReview = member.FlightReviews.OrderByDescending(r => r.Date).First();
                viewModel.TotalTime   = lastReview.TotalTime;
                viewModel.RetractTime = lastReview.RetractTime;
            }
            viewModel.ReviewDate = DateTime.Now;

            return(View(ViewNames.UpdateFlightReview, viewModel));
        }
        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 UpdateFlightReview(FlightReviewViewModel viewModel)
        {
            Member pilot = _dataService.GetMember(viewModel.PilotId);

            FlightReview review = new FlightReview()
            {
                Date            = (DateTime)viewModel.ReviewDate,
                InstructorName  = viewModel.InstructorName,
                InstructorNotes = viewModel.Notes,
                PilotId         = viewModel.PilotId,
                ReviewType      = viewModel.ReviewType,
                RetractTime     = viewModel.RetractTime,
                TotalTime       = viewModel.TotalTime
            };

            _dataService.AddFlightReview(review);

            return(PilotReview(pilot.Id));
        }
Beispiel #5
0
        public void ImportReviews()
        {
            IEnumerator <NtfcDataSet.BFRRow> rows = _dataSet.BFR.GetEnumerator();
            List <Member> members = _dbContext.Members.Include(m => m.Login).ToList();

            foreach (var member in members)
            {
                NtfcDataSet.BFRRow srcLastReview = _dataSet.BFR
                                                   .Where(r => r.Member_ID == member.Login.MemberPIN && !r.IsInstructor_MIDNull())
                                                   .OrderByDescending(r => r.Review_date)
                                                   .FirstOrDefault();

                if (member.Login.MemberPIN == "537")
                {
                    System.Diagnostics.Debug.WriteLine("Flight review 537");
                }

                if (srcLastReview != null && !srcLastReview.IsReview_dateNull())
                {
                    Member       instructor   = _dbContext.Members.FirstOrDefault(m => m.Login.MemberPIN == srcLastReview.Instructor_MID);
                    FlightReview flightReview = new FlightReview()
                    {
                        Date           = srcLastReview.Review_date,
                        Pilot          = member,
                        InstructorName = instructor.FullName
                    };
                    if (!srcLastReview.Istotal_timeNull())
                    {
                        flightReview.TotalTime = Single.Parse(srcLastReview.total_time);
                    }

                    if (!srcLastReview.Isretract_timeNull())
                    {
                        flightReview.RetractTime = Single.Parse(srcLastReview.retract_time);
                    }

                    _dbContext.FlightReviews.Add(flightReview);
                }
            }
            _dbContext.SaveChanges();
        }