Esempio n. 1
0
        public ActionResult Create(ReservationViewModel model)
        {
            if (ModelState.IsValid)
            {
                ValidateReservation(model);
            }

            if (ModelState.IsValid)
            {
                _dataService.SaveReservation(model.ConvertToReservation());

                if (model.InstructorId != 0)
                {
                    try
                    {
                        Member   pilot      = _dataService.GetMember(model.MemberId);
                        Member   instructor = _dataService.GetMember((int)model.InstructorId);
                        Aircraft aircraft   = _dataService.GetAircraftById(model.AircraftId);

                        MailMessage message = new MailMessage();
                        message.From = new MailAddress("*****@*****.**");
                        message.To.Add(new MailAddress(instructor.Login.Email));

                        message.Subject = "Flight lesson notification";
                        message.Body    = "NTXFC club member " + pilot.FullName
                                          + " has scheduled flight lesson in " + aircraft.RegistrationNumber
                                          + " starting at " + model.StartTime + " on " + model.StartDate.ToString("yyyy-MM-dd") + "\t"
                                          + "If you are not able please contact pilot at " + pilot.Login.Email + " or " + pilot.Phone + "\t";

                        SendEmail(message);
                    }
                    catch (Exception ex)
                    {
                        string msg = "Error while trying to send Reservation notification:\t" + ex.ToString();
                        LogError(msg);
                    }
                }

                return(RedirectToAction("AircraftByWeek", new { aircraftId = model.AircraftId, startDate = model.StartDate }));
            }

            model.AircraftList   = _dataService.GetAllAirplanes();
            model.InstructorList = _dataService.GetMembersByRoleAndStatus(UserRoles.Instructor, MemberStatus.Active);
            model.TimeList       = new List <DateTime>().GetListFromRange(DateTime.MinValue.AddHours(6), DateTime.MinValue.AddHours(22),
                                                                          new TimeSpan(0, 30, 0)).ConvertAll(x => new SelectListItem()
            {
                Value = x.ToString("HH:mm"), Text = x.ToString("HH:mm")
            }).ToList();

            model.AircraftList.Insert(0, new Aircraft());
            model.InstructorList.Insert(0, new Member());

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Create(CreateSquawkViewModel model)
        {
            if (ModelState.IsValid)
            {
                Squawk squawk = new Squawk()
                {
                    AircraftId     = model.AircraftId,
                    Subject        = model.Subject,
                    Description    = model.Description,
                    GroundAircraft = model.GroundAircraft,
                    PostedById     = ProfileCommon.GetProfile().MemberId,
                    PostedOn       = DateTime.Now,
                    Status         = SquawkStatus.Open.ToString()
                };
                _dataService.AddSquawk(squawk);

                if (model.GroundAircraft)
                {
                    _dataService.UpdateAircraftStatus(model.AircraftId, AircraftStatus.Grounded.ToString());
                }

                try
                {
                    Aircraft aircraft = _dataService.GetAircraftById(model.AircraftId);

                    MailMessage message = new MailMessage();
                    message.Subject = "Squawk posted for " + aircraft.RegistrationNumber;
                    message.From    = new MailAddress("*****@*****.**");
                    message.Body    = model.Subject + "\t";
                    message.Body   += model.Description;

                    List <Member> owners = _dataService.GetAircraftOwners(model.AircraftId);
                    foreach (var owner in aircraft.Owners)
                    {
                        message.To.Add(new MailAddress(owner.Login.Email));
                    }

                    SendEmail(message);
                }
                catch (Exception ex)
                {
                    LogError("Error while sending squawk notification email for aircraftId " + model.AircraftId + "\t" + ex.ToString());
                }

                return(RedirectToAction("ListActiveSquawks"));
            }

            return(View(model));
        }
        /// <summary>
        /// GET: /Aircraft/Details/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(int id)
        {
            Aircraft aircraft = _dataService.GetAircraftById(id);

            if (aircraft == null)
            {
                throw new HttpException(404, "Aircraft not found");
            }

            AircraftImageListViewModel imageModel = new AircraftImageListViewModel();

            imageModel.ImageList = aircraft.Images;

            AircraftDetailsViewModel model = new AircraftDetailsViewModel()
            {
                Aircraft       = aircraft,
                AircraftImages = imageModel
            };

            return(View(model));
        }
        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);
        }