Beispiel #1
0
        public static ManualCreate GetViewModel(BaseController baseController)
        {
            var manualCreate = new ManualCreate();
            manualCreate.Ensure(baseController);

            return manualCreate;
        }
Beispiel #2
0
        public static TaskIndex GetViewModel(BaseController baseController)
        {
            PeopleContactTask[] peopleContactTasks = PeopleContactCache.GetPeopleContactTasks(baseController.Db, baseController.UserId);
            var taskIndex = new TaskIndex
            {
                ActualTasks = peopleContactTasks.Where(pct => pct.PeopleContactTaskType == PeopleContactTaskType.Actual).ToArray(),
                DelayedTasks = peopleContactTasks.Where(pct => pct.PeopleContactTaskType == PeopleContactTaskType.Delayed).ToArray()
            };

            return taskIndex;
        }
        private void ValidateConfirms(BaseController baseController)
        {
            if (!ConfirmTermsAndConditions)
            {
                baseController.ModelState.AddModelError(BaseCache.ConfirmTermsAndConditionsField, ValidationResource.PeopleContact_NotConfirmedTermsAndConditions_ErrorMessage);
            }

            if (!ConfirmPersonalData)
            {
                baseController.ModelState.AddModelError(BaseCache.ConfirmPersonalDataField, ValidationResource.PeopleContact_NotConfirmedPersonalData_ErrorMessage);
            }
        }
Beispiel #4
0
        public static ManualCreate GetViewModel(BaseController baseController, ManualCreate manualCreate)
        {
            manualCreate.Ensure(baseController);
            manualCreate.Validate(baseController);

            if (!baseController.ModelState.IsValid)
                return manualCreate;

            Manual manual = manualCreate.GetModel();
            ManualCache.Insert(baseController.Db, manual);

            return manualCreate;
        }
Beispiel #5
0
 public void Validate(BaseController baseController)
 {
     ValidateEmailBodies(baseController);
     CalculateFolderRemainMB(baseController.Server, FileStore.Videos);
     ValidateFile(baseController, File, FileStore.Videos, Properties.Settings.Default.MaxVideoUploadSizeMB, allowedExtensions: AllowedExtensions);
 }
Beispiel #6
0
        public static UserProfilePromote GetViewModel(BaseController baseController, int id, string returnUrl)
        {
            var allowedReturnUrl = new[] { "Index", "IndexTree" };
            if (baseController == null || id == 0 || !allowedReturnUrl.Contains(returnUrl))
                return null;

            var userProfilePromote = new UserProfilePromote(baseController, id, returnUrl);
            userProfilePromote.Validate();
            userProfilePromote.Process();

            return userProfilePromote;
        }
Beispiel #7
0
 private ManualsByTypeIndex(BaseController baseController, ManualType manualType, int pageNumber, int pageSize)
 {
     Title = String.Format("{0} - {1}", ViewResource.ManualsByType_Index_Title_Text, manualType.Title);
     Manuals = manualType.Manuals.OrderBy(m => m.Order).Select(m => new ManualDashboard.Manual(baseController, m)).ToPagedList(pageNumber, pageSize);
 }
Beispiel #8
0
        public static ManualPlayer GetViewModel(BaseController baseController, int id)
        {
            Manual manual = ManualCache.GetDetail(baseController.Db, id);
            if (manual == null)
                return null;

            var manualPlayer = new ManualPlayer(baseController, manual);
            return manualPlayer;
        }
Beispiel #9
0
        private ManualPlayer(BaseController baseController, Manual manual)
        {
            _isValid = true;
            _baseController = baseController;
            _manual = manual;
            _contentType = HttpResponseBaseService.ContentType.Txt;

            if (baseController == null || manual == null || (!manual.IsAccessForAuthGuest && baseController.IsAuthenticatedGuest))
            {
                _isValid = false;
                return;
            }

            Title = manual.Title;
            PlayerDataUrl = baseController.Url.Action("PlayerData", "Manual", new { id = manual.ManualId });

            ProcessFindFilePath();
            CheckPlayer();
        }
Beispiel #10
0
        public static ManualDelete GetViewModel(BaseController baseController, int id)
        {
            Manual manual = ManualCache.GetDetail(baseController.Db, id);
            if (manual == null)
                return null;

            var manualDelete = new ManualDelete(manual);
            return manualDelete;
        }
Beispiel #11
0
            public Manual(BaseController baseController, Models.Manual manual)
            {
                string token = Cryptography.Encrypt(manual.ManualId.ToString(CultureInfo.InvariantCulture));
                bool canRead = !baseController.IsAuthenticatedGuest || baseController.IsAuthenticatedGuest && manual.IsAccessForAuthGuest;
                bool canDownload = canRead && manual.IsDownloadable;

                Title = manual.Title;
                Token = token;
                CanRead = canRead;
                CanDownload = canDownload;
            }
Beispiel #12
0
        public static ManualDashboard GetViewModel(BaseController baseController)
        {
            Models.ManualType[] manualTypes = ManualTypeCache.GetIndex(baseController.Db);
            if (manualTypes == null)
                return null;

            var manualDashboard = new ManualDashboard(baseController, manualTypes);
            return manualDashboard;
        }
Beispiel #13
0
 public ManualDashboard(BaseController baseController, IEnumerable<Models.ManualType> manualTypes)
 {
     _baseController = baseController;
     Models.ManualType[] orderedManualTypes = manualTypes.OrderBy(mt => mt.Order).ToArray();
     ManualTypeItems = orderedManualTypes.Select(GetManualTypeItem).ToArray();
     ManualTypes = orderedManualTypes.Select(GetManualType).ToArray();
 }
Beispiel #14
0
 protected void ValidateManualType(BaseController baseController)
 {
     if (ManualTypeId == 0)
     {
         baseController.ModelState.AddModelError(BaseCache.ManualTypeIdField, String.Format(ValidationResource.Global_Required_ErrorMessage, FieldResource.ManualType_Title_Name));
     }
 }
Beispiel #15
0
 protected void Ensure(BaseController baseController)
 {
     CalculateFolderRemainMB(baseController.Server, FileStore.Manuals);
     PopulateManualTypeId(baseController.ViewBag, baseController.Db, ManualTypeId == 0 ? null : (object)ManualTypeId);
 }
Beispiel #16
0
        private void ValidateManualFile(BaseController baseController)
        {
            if (File == null)
                return;

            var dbManual = ManualCache.GetDetail(baseController.Db, ManualId);
            if (dbManual == null)
                throw new Exception("Cannot validate ManualEdit due to empty ManualId.");

            RelativeFilePath = dbManual.RelativeFilePath;

            string previousFileName = Path.GetFileName(RelativeFilePath);
            ValidateFile(baseController, File, FileStore.Manuals, Properties.Settings.Default.MaxManualUploadSizeMB, previousFileName, AllowedExtensions);
        }
Beispiel #17
0
        public static IPagedList<ManualIndex> GetViewModel(BaseController baseController, int? page, int pageSize)
        {
            int pageNumber;
            ProcessPaging(page, out pageNumber);

            PopulatePageSize(baseController.ViewBag, pageSize);

            ManualIndex[] manuals = ManualCache.GetIndex(baseController.Db).Select(m => new ManualIndex(m)).ToArray();
            IPagedList<ManualIndex> viewModel = manuals.ToPagedList(pageNumber, pageSize);
            return viewModel;
        }
Beispiel #18
0
        public static ManualDelete GetViewModel(BaseController baseController, int id, out DeleteResult deleteResult)
        {
            deleteResult = DeleteResult.Ok;

            Manual manual = ManualCache.GetDetail(baseController.Db, id);
            if (manual == null)
                return null;

            var manualDelete = new ManualDelete(manual);
            manualDelete.Process(baseController);

            if (baseController.ModelState.IsValid)
            {
                deleteResult = ManualCache.Delete(baseController.Db, manual);

                switch (deleteResult)
                {
                    case DeleteResult.Ok:
                    case DeleteResult.AuthorizationFailed:
                        return manualDelete;

                    case DeleteResult.DbFailed:
                        baseController.ModelState.AddModelError(BaseCache.TitleField, ValidationResource.Global_DeleteRecord_ErrorMessage);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            return manualDelete;
        }
Beispiel #19
0
 private void Validate(BaseController baseController)
 {
     ValidateManualType(baseController);
     ValidateFile(baseController, File, FileStore.Manuals, Properties.Settings.Default.MaxManualUploadSizeMB, allowedExtensions: AllowedExtensions);
 }
Beispiel #20
0
 private void Process(BaseController baseController)
 {
     ProcessManualFile(baseController);
 }
Beispiel #21
0
        public static ManualPlayer GetViewModel(BaseController baseController, string token)
        {
            string decryptedToken = Cryptography.Decrypt(token);
            if (String.IsNullOrEmpty(decryptedToken))
                return null;

            int id;
            if (!Int32.TryParse(decryptedToken, out id))
                return null;

            var manualPlayer = GetViewModel(baseController, id);
            return manualPlayer;
        }
Beispiel #22
0
 private ManualDetail(BaseController baseController, Manual manual)
 {
     ManualId = manual.ManualId;
     Title = manual.Title;
     ManualTypeTitle = manual.ManualType.Title;
     Order = manual.Order;
     Url = baseController.Url.Action("Player", "Manual", new { id = manual.ManualId });
     IsDownloadable = manual.IsDownloadable;
     IsAccessForAuthGuest = manual.IsAccessForAuthGuest;
 }
Beispiel #23
0
        public static ManualsByTypeIndex GetViewModel(BaseController baseController, int id, int? page, int pageSize)
        {
            int pageNumber;
            ProcessPaging(page, out pageNumber);

            PopulatePageSize(baseController.ViewBag, pageSize);

            ManualType manualType = ManualTypeCache.GetDetail(baseController.Db, id);
            if (manualType == null)
                return null;

            var viewModel = new ManualsByTypeIndex(baseController, manualType, pageNumber, pageSize);
            return viewModel;
        }
Beispiel #24
0
        public static ManualEdit GetViewModel(BaseController baseController, int id)
        {
            Manual manual = ManualCache.GetDetail(baseController.Db, id);
            if (manual == null)
                return null;

            var manualEdit = new ManualEdit(manual);
            manualEdit.Ensure(baseController);

            return manualEdit;
        }
 public void Validate(BaseController baseController)
 {
     ValidateFile(baseController, File, FileStore.None, 4);
     ValidateConfirms(baseController);
 }
Beispiel #26
0
        public static ManualEdit GetViewModel(BaseController baseController, ManualEdit manualEdit)
        {
            manualEdit.Ensure(baseController);
            manualEdit.Validate(baseController);

            if (!baseController.ModelState.IsValid)
                return manualEdit;

            Manual manual = manualEdit.GetModel();
            bool success = ManualCache.Update(baseController.Db, manual);
            return success ? manualEdit : null;
        }
Beispiel #27
0
 private UserProfilePromote(BaseController baseController, int id, string returnUrl)
 {
     BaseController = baseController;
     _userId = id;
     ReturnUrl = returnUrl;
 }
Beispiel #28
0
 private void Validate(BaseController baseController)
 {
     ValidateManualType(baseController);
     ValidateManualFile(baseController);
 }
Beispiel #29
0
        protected void ValidateFile(BaseController baseController, HttpPostedFileBase file, FileStore fileStore, int maxContentLengthMB, string previousFileName = null, string[] allowedExtensions = null)
        {
            if (!baseController.ModelState.IsValid)
                return;

            if (file == null)
            {
                baseController.ModelState.AddModelError(BaseCache.FileField, String.Format(ValidationResource.Global_Required_ErrorMessage, FieldResource.Global_ImportFile_Name));
                return;
            }

            string fixedFileName = Path.GetFileName(file.FileName) ?? "___error.nfo";
            if (allowedExtensions != null && allowedExtensions.Length > 0)
            {
                string fileExtension = Path.GetExtension(fixedFileName);
                if (allowedExtensions.All(ae => !ae.Equals(fileExtension, StringComparison.InvariantCultureIgnoreCase)))
                {
                    baseController.ModelState.AddModelError(BaseCache.FileField, ValidationResource.Global_IncorrectFileFormat_ErrorMessage);
                    return;
                }
            }

            if (fixedFileName.Length > 100)
            {
                baseController.ModelState.AddModelError(BaseCache.FileField, ValidationResource.Global_BadFileName_ErrorMessage);
                return;
            }

            if (file.ContentLength == 0)
            {
                baseController.ModelState.AddModelError(BaseCache.FileField, ValidationResource.Global_FileIsEmpty_ErrorMessage);
                return;
            }

            if (file.ContentLength > 1024 * 1024 * (long)maxContentLengthMB)
            {
                baseController.ModelState.AddModelError(BaseCache.FileField, String.Format(ValidationResource.Global_FileIsTooLarge_ErrorMessage, maxContentLengthMB));
                return;
            }

            if (fileStore == FileStore.None)
                return;

            if (file.ContentLength > FolderRemainMB * (long)1048576)
            {
                baseController.ModelState.AddModelError(BaseCache.FileField, ValidationResource.Global_StoreIsFull_ErrorMessage);
                return;
            }

            string absoluteFolderPath;
            string relativeFolderPath;
            int folderQuota;
            GetFolderPath(baseController.Server, fileStore, out absoluteFolderPath, out relativeFolderPath, out folderQuota);

            string absolutePreviousFilePath = String.IsNullOrEmpty(previousFileName) ? null : Path.Combine(absoluteFolderPath, previousFileName);
            string absoluteFilePath = Path.Combine(absoluteFolderPath, fixedFileName);
            if (File.Exists(absoluteFilePath) && !absoluteFilePath.Equals(absolutePreviousFilePath, StringComparison.InvariantCultureIgnoreCase))
            {
                baseController.ModelState.AddModelError(BaseCache.FileField, ValidationResource.Global_FileExists_ErrorMessage);
                return;
            }

            if (!String.IsNullOrEmpty(absolutePreviousFilePath) && File.Exists(absolutePreviousFilePath))
            {
                File.Delete(absolutePreviousFilePath);
            }

            try
            {
                file.SaveAs(absoluteFilePath);

                RelativeFilePath = Path.Combine(relativeFolderPath, fixedFileName);

                var converter = new Converter(baseController.Server);
                VideoFile videoFile = converter.GetVideoInfo(absoluteFilePath);
                VideoDuration = Convert.ToInt32(videoFile.Duration.TotalSeconds);
            }
            catch (Exception e)
            {
                try
                {
                    if (File.Exists(absoluteFilePath))
                    {
                        File.Delete(absoluteFilePath);
                    }
                }
                catch (Exception ex)
                {
                    Logger.SetLog(ex);
                }

                Logger.SetLog(e);
                baseController.ModelState.AddModelError(BaseCache.FileField, ValidationResource.Global_FileCannotBeSaved_ErrorMessage);
            }
        }
Beispiel #30
0
        public void ValidateVideoFile(BaseController baseController)
        {
            if (File == null)
                return;

            var dbVideo = VideoCache.GetDetail(baseController.Db, VideoId);
            if (dbVideo == null)
                throw new Exception("Cannot validate VideoEdit due to empty VideoId.");

            RelativeFilePath = dbVideo.RelativeFilePath;
            CalculateFolderRemainMB(baseController.Server, FileStore.Videos);

            string previousFileName = Path.GetFileName(RelativeFilePath);
            ValidateFile(baseController, File, FileStore.Videos, Properties.Settings.Default.MaxVideoUploadSizeMB, previousFileName, AllowedExtensions);
        }