示例#1
0
        public IActionResult EditDocument(int documentId)
        {
            EditDocumentView model = new EditDocumentView();

            var document = _documentsService.GetDocumentById(documentId);

            if (document.DepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            if (document.AdminsOnly && !ClaimsAuthorizationHelper.IsUserDepartmentAdmin())
            {
                Unauthorized();
            }

            model.Name        = document.Name;
            model.Description = document.Description;
            model.Category    = document.Category;
            model.AdminOnly   = document.AdminsOnly.ToString();
            model.Document    = document;
            model.UserId      = UserId;

            return(View(model));
        }
示例#2
0
        private void NewDocument()
        {
            var document = new Document {
                IssueDate = DateTime.Today
            };
            var vm = new EditDocumentViewModel(new UnitOfWorkFactory(), document);

            vm.Init();
            var window = new EditDocumentView(vm);

            if (window.ShowDialog() ?? false)
            {
                DocumentList.Add(document);
            }
        }
示例#3
0
        public IActionResult EditDocument(EditDocumentView model, IFormFile fileToUpload)
        {
            var document = _documentsService.GetDocumentById(model.DocumentId);

            if (document.DepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            if (document.AdminsOnly && !ClaimsAuthorizationHelper.IsUserDepartmentAdmin())
            {
                Unauthorized();
            }

            if (fileToUpload != null && fileToUpload.Length > 0)
            {
                var extenion = fileToUpload.FileName.Substring(fileToUpload.FileName.IndexOf(char.Parse(".")) + 1,
                                                               fileToUpload.FileName.Length - fileToUpload.FileName.IndexOf(char.Parse(".")) - 1);

                if (!String.IsNullOrWhiteSpace(extenion))
                {
                    extenion = extenion.ToLower();
                }

                if (extenion != "jpg" && extenion != "jpeg" && extenion != "png" && extenion != "gif" && extenion != "gif" && extenion != "pdf" && extenion != "doc" &&
                    extenion != "docx" && extenion != "ppt" && extenion != "pptx" && extenion != "pps" && extenion != "ppsx" && extenion != "odt" &&
                    extenion != "xls" && extenion != "xlsx" && extenion != "mp3" && extenion != "m4a" && extenion != "ogg" && extenion != "wav" &&
                    extenion != "mp4" && extenion != "m4v" && extenion != "mov" && extenion != "wmv" && extenion != "avi" && extenion != "mpg" && extenion != "txt")
                {
                    ModelState.AddModelError("fileToUpload", "Document type (extension) is not importable.");
                }

                if (fileToUpload.Length > 10000000)
                {
                    ModelState.AddModelError("fileToUpload", "Document is too large, must be smaller then 10MB.");
                }
            }

            if (ModelState.IsValid)
            {
                document.Name        = model.Name;
                document.Description = model.Description;

                if (ClaimsAuthorizationHelper.IsUserDepartmentAdmin())
                {
                    document.AdminsOnly = bool.Parse(model.AdminOnly);
                }
                else
                {
                    document.AdminsOnly = false;
                }

                document.Category = model.Category;

                if (fileToUpload != null && fileToUpload.Length > 0)
                {
                    document.Type     = fileToUpload.ContentType;
                    document.Filename = fileToUpload.FileName;

                    byte[] uploadedFile = new byte[fileToUpload.OpenReadStream().Length];
                    fileToUpload.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length);

                    document.Data = uploadedFile;
                }

                _documentsService.SaveDocument(document);

                return(RedirectToAction("Index", "Documents", new { Area = "User" }));
            }

            return(View(model));
        }