public ActionResult AddLogPage(AircraftLogModel viewModel, HttpPostedFileBase fileBase)
        {
            string relFolderUrl = Url.Content("~/Content/AircraftLogs/" + viewModel.RegistrationNumber);
            string absFolderUrl = Server.MapPath(relFolderUrl);
            string origFileUrl  = Server.MapPath(Path.Combine(relFolderUrl, viewModel.EditPageNumber.ToString() + "orig.jpg"));
            string pageFileName = viewModel.EditPageNumber.ToString() + ".jpg";
            string pageUrl      = Server.MapPath(Path.Combine(relFolderUrl, pageFileName));

            if (System.IO.File.Exists(pageUrl))
            {
                ModelState.AddModelError(String.Empty, "The page number " + viewModel.EditPageNumber.ToString() + " already exists. Please delete it first or use different number.");
                return(ViewLog(viewModel.AircraftId, viewModel.RegistrationNumber));
            }

            if (!System.IO.Directory.Exists(absFolderUrl))
            {
                System.IO.Directory.CreateDirectory(absFolderUrl);
            }

            fileBase.SaveAs(origFileUrl);
            ImageHelper.ScaleToWidth(origFileUrl, pageUrl, 800);

            if (System.IO.File.Exists(pageUrl))
            {
                Aircraft aircraft = _dataService.GetAircraftById(viewModel.AircraftId);
                aircraft.LogUpdloadedOn        = DateTime.Now;
                aircraft.LogUploadedByMemberId = ProfileCommon.GetUserProfile().MemberId;
                _dataService.UpdateAircraft(aircraft);

                System.IO.File.Delete(origFileUrl);
            }

            ModelState.Clear();
            return(ViewLog(viewModel.AircraftId, viewModel.RegistrationNumber));
        }
        public ActionResult AddLogPage(AircraftLogModel viewModel, HttpPostedFileBase fileBase)
        {
            string relFolderUrl = Url.Content("~/Content/AircraftLogs/" + viewModel.RegistrationNumber);
            string absFolderUrl = Server.MapPath(relFolderUrl);
            string origFileUrl = Server.MapPath(Path.Combine(relFolderUrl, viewModel.EditPageNumber.ToString() + "orig.jpg"));
            string pageFileName = viewModel.EditPageNumber.ToString() + ".jpg";
            string pageUrl = Server.MapPath(Path.Combine(relFolderUrl, pageFileName));
            if (System.IO.File.Exists(pageUrl))
            {
                ModelState.AddModelError(String.Empty, "The page number " + viewModel.EditPageNumber.ToString() + " already exists. Please delete it first or use different number.");
                return ViewLog(viewModel.AircraftId, viewModel.RegistrationNumber);
            }

            if (!System.IO.Directory.Exists(absFolderUrl))
                System.IO.Directory.CreateDirectory(absFolderUrl);

            fileBase.SaveAs(origFileUrl);
            ImageHelper.ScaleToWidth(origFileUrl, pageUrl, 800);

            if (System.IO.File.Exists(pageUrl))
            {
                Aircraft aircraft = _dataService.GetAircraftById(viewModel.AircraftId);
                aircraft.LogUpdloadedOn = DateTime.Now;
                aircraft.LogUploadedByMemberId = ProfileCommon.GetUserProfile().MemberId;
                _dataService.UpdateAircraft(aircraft);

                System.IO.File.Delete(origFileUrl);
            }

            ModelState.Clear();
            return ViewLog(viewModel.AircraftId, viewModel.RegistrationNumber);
        }
        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));
        }
        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);
        }