public async Task <IActionResult> Upload(UploadInputModel input)
        {
            var candidateId = this.candidatesService.GetCandidateIdByUsername(this.User.Identity.Name);

            if (candidateId == null)
            {
                return(this.RedirectToAction("CreateProfile", "Candidates"));
            }

            if (!this.ModelState.IsValid)
            {
                input.FileExtensions = this.allowedExtensions;
                input.Categories     = this.allowedCategories;
                return(this.View(input));
            }

            if (this.documentsService.DocumentNameAlreadyExists(input.SanitizedFileName, candidateId))
            {
                this.ModelState.AddModelError(string.Empty, GlobalConstants.DocumentAlreadyExists);
                input.FileExtensions = this.allowedExtensions;
                input.Categories     = this.allowedCategories;
                return(this.View(input));
            }

            if (!this.allowedExtensions.Any(ae => input.File.FileName.EndsWith(ae)))
            {
                this.ModelState.AddModelError(string.Empty, GlobalConstants.FileExtensionNotSupported);
                input.FileExtensions = this.allowedExtensions;
                input.Categories     = this.allowedCategories;
                return(this.View(input));
            }

            if (this.documentsService.GetDocumentCountForCandidate(candidateId) > 15)
            {
                this.ModelState.AddModelError(string.Empty, GlobalConstants.FIleCountReached);
                input.FileExtensions = this.allowedExtensions;
                input.Categories     = this.allowedCategories;
                return(this.View(input));
            }

            var documentId = await this.documentsService.UploadAsync(input, candidateId);

            if (documentId == null)
            {
                return(this.RedirectToAction("Error", "Home"));
            }

            this.TempData["Success"] = GlobalConstants.DocumentSuccessfullyUploaded;
            return(this.RedirectToAction(nameof(this.All)));
        }
        public IActionResult Upload()
        {
            var candidateId = this.candidatesService.GetCandidateIdByUsername(this.User.Identity.Name);

            if (candidateId == null)
            {
                return(this.RedirectToAction("CreateProfile", "Candidates"));
            }

            var viewModel = new UploadInputModel
            {
                FileExtensions = this.allowedExtensions,
                Categories     = this.allowedCategories,
            };

            return(this.View(viewModel));
        }
예제 #3
0
        public async Task UploadAsyncSavesFileSuccessfully()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();

            var repository       = new EfDeletableEntityRepository <Document>(context);
            var cloudinary       = new Cloudinary(new Account(CloudinaryConfig.CloudName, CloudinaryConfig.ApiKey, CloudinaryConfig.ApiSecret));
            var documentsService = this.GetMockedService(repository, null, cloudinary);

            var model = new UploadInputModel
            {
                DocumentCategoryId = 123,
                File = this.PrepareFile(),
            };

            var result = await documentsService.UploadAsync(model, "1");

            Assert.NotNull(result);
            Assert.Equal(1, context.Documents.Count());
        }
예제 #4
0
 public UploadModel Upload(UploadInputModel uploadInputModel)
 {
     return(Post <UploadModel, UploadInputModel>("core_files_upload", uploadInputModel));
 }