Beispiel #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));
        }
Beispiel #2
0
        public ViewResult Details(int id)
        {
            Squawk squawk = _dataService.GetSquawkById(id);

            SquawkDetailViewModel model = new SquawkDetailViewModel()
            {
                AircraftId         = squawk.AircraftId,
                Description        = squawk.Description,
                Id                 = squawk.Id,
                PostedBy           = squawk.PostedBy.FullName,
                PostedOn           = squawk.PostedOn,
                RegistrationNumber = squawk.Aircraft.RegistrationNumber,
                ResolvedOn         = squawk.ResolvedOn,
                ResolutionNotes    = squawk.ResolutionNotes,
                Status             = squawk.Status,
                Subject            = squawk.Subject
            };

            if (squawk.ResolvedById != null)
            {
                Member resolvedBy = _dataService.GetMember((int)squawk.ResolvedById);
                model.ResolvedBy = resolvedBy.FullName;
            }

            foreach (var comment in squawk.Comments)
            {
                SquawkCommentViewModel commentVM = new SquawkCommentViewModel()
                {
                    Id         = comment.Id,
                    PostedById = comment.PostedByMemberId,
                    PostedOn   = comment.PostDate,
                    Text       = comment.Text
                };

                Member poster = _dataService.GetMember(comment.PostedByMemberId);
                commentVM.PostedBy = poster.FullName;

                model.Comments.Add(commentVM);
            }

            return(View(ViewNames.SquawkDetails, model));
        }
        public ActionResult InstructorDetails(int memberId)
        {
            InstructorData instructor = _dataService.GetInstructorInfoByMemberId(memberId);
            Member         member     = _dataService.GetMember(memberId);

            InstructorViewModel instructorVM = new InstructorViewModel()
            {
                MemberId = instructor.MemberId,
                AltPhone = member.Phone,
                AvailableForCheckoutsAnnuals = instructor.AvailableForCheckoutsAnnuals,
                InstructOnWeekdayNights      = instructor.InstructOnWeekdayNights,
                InstructOnWeekdays           = instructor.InstructOnWeekdays,
                InstructOnWeekends           = instructor.InstructOnWeekends,
                CeritifcateNumber            = instructor.CertificateNumber,
                Comments = instructor.Comments,
                DesignatedForStageChecks = instructor.DesignatedForStageChecks,
                Email    = member.Login.Email,
                FullName = member.FullName,
                Id       = instructor.Id,
                Phone    = member.Phone,
                Ratings  = instructor.Ratings
            };

            if (instructor.AuthorizedAircraft != null)
            {
                instructorVM.AuthorizedAircraft = new List <AircraftListItemViewModel>();

                foreach (var ac in instructor.AuthorizedAircraft)
                {
                    AircraftListItemViewModel avm = new AircraftListItemViewModel
                    {
                        Id = ac.AircraftId,
                        RegistrationNumber = ac.Aircraft.RegistrationNumber
                    };
                    instructorVM.AuthorizedAircraft.Add(avm);
                }
            }

            return(View(ViewNames.InstructorDetails, instructorVM));
        }
        /// <summary>
        /// GET: /Member/Details/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ViewResult Details(int id)
        {
            Member member = _dataService.GetMember(id);

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

            MemberViewModel model = member.ConvertToViewModel();

            model.UserName = member.Login.Username;
            return(View(model));
        }
        public ActionResult ViewLog(int aircraftId, string regNum)
        {
            AircraftLogModel vm = new AircraftLogModel();

            vm.AircraftId         = aircraftId;
            vm.RegistrationNumber = regNum;

            Aircraft aircraft = _dataService.GetAircraftById(vm.AircraftId);

            vm.LastUpdatedOn = aircraft.LogUpdloadedOn;
            if (vm.LastUpdatedOn != null)
            {
                Member member = _dataService.GetMember((int)aircraft.LogUploadedByMemberId);
                vm.UpdatedBy = member.FullName;
            }

            string relFolderUrl = Url.Content("~/Content/AircraftLogs/" + regNum);
            string absFolderUrl = Server.MapPath(relFolderUrl);

            if (System.IO.Directory.Exists(absFolderUrl))
            {
                string[] files = System.IO.Directory.GetFiles(Server.MapPath(relFolderUrl));
                if (files.Length > 0)
                {
                    vm.Pages = new List <LogPageModel>();
                    for (int i = 0; i < files.Length; ++i)
                    {
                        string       fileName = Path.GetFileName(files[i]);
                        LogPageModel page     = new LogPageModel()
                        {
                            PageNumber = Int32.Parse(Path.GetFileNameWithoutExtension(fileName)),
                            Url        = relFolderUrl + "/" + fileName
                        };
                        vm.Pages.Add(page);
                        vm.Pages.Sort();
                    }
                }
            }

            if (vm.Pages != null)
            {
                vm.EditPageNumber = vm.Pages.Last().PageNumber + 1;
            }
            else
            {
                vm.EditPageNumber = 1;
            }

            if (User.IsInRole(FlyingClub.Common.UserRoles.Admin.ToString()) ||
                User.IsInRole(FlyingClub.Common.UserRoles.AircraftOwner.ToString()) ||
                User.IsInRole(FlyingClub.Common.UserRoles.AircraftMaintenance.ToString()))
            {
                vm.CanEdit = true;
            }
            else
            {
                vm.CanEdit = false;
            }

            return(View("MaintenanceLog", vm));
        }