Example #1
0
        public async Task <Database.Models.Entity.File> SaveFile(UploadAttachmentModel upload)
        {
            var fileId = Guid.NewGuid().ToString("N");

            var path = Path.Combine(_fileStoragePath, fileId);

            byte[] encryptedData;

            // Encrypt file contents before saving

            using (var ms = new MemoryStream())
            {
                await upload.File.CopyToAsync(ms);

                var sourceData = ms.ToArray();
                encryptedData = Encryption.Encrypt(sourceData, fileId);
            }

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await stream.WriteAsync(encryptedData);
            }

            return(new Database.Models.Entity.File
            {
                FileName = upload.File.Name,
                ContentType = upload.File.ContentType,
                FileId = fileId
            });
        }
Example #2
0
        public async Task UploadFileToDocument(UploadAttachmentModel upload)
        {
            using (var unitOfWork = await DataConnectionFactory.CreateUnitOfWork())
            {
                var document = await unitOfWork.Documents.GetById(upload.DocumentId);

                if (document == null)
                {
                    throw new NotFoundException("Document not found.");
                }

                if (document.FileId.HasValue)
                {
                    throw new LogicException("A file is already attached to this document.");
                }

                var file = await _fileProvider.SaveFile(upload);

                document.Attachment = file;

                await unitOfWork.Documents.Update(document);

                await unitOfWork.SaveChangesAsync();
            }
        }
Example #3
0
        public async Task UploadAttachmentToDocument(UploadAttachmentModel upload)
        {
            var existingFile = await _fileRepository.GetByDocumentId(upload.DocumentId);

            if (existingFile != null)
            {
                throw new LogicException("A file is already attached to this document.");
            }

            var fileExtension = Path.GetExtension(upload.File.FileName);

            string fileId = await _fileProvider.UploadFile(upload);

            var file = new Database.Models.Entity.File
            {
                FileId      = fileId,
                FileName    = upload.File.FileName,
                ContentType = upload.File.ContentType,
                DocumentId  = upload.DocumentId
            };

            _fileRepository.Create(file);

            await _fileRepository.SaveChanges();
        }
Example #4
0
        public async Task <string> UploadFile(UploadAttachmentModel upload)
        {
            var fileName = Path.GetRandomFileName();

            var path = Path.Combine(_fileStoragePath, fileName);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await upload.File.CopyToAsync(stream);
            }

            return(fileName);
        }
Example #5
0
        public override async Task <string> UploadFile(UploadAttachmentModel upload)
        {
            var metadata = new File();

            metadata.Name = upload.File.FileName;

            var request = _driveService.Files.Create(metadata, upload.File.OpenReadStream(), upload.File.ContentType);

            await request.UploadAsync();

            var result = request.ResponseBody;

            return(result.Id);
        }
Example #6
0
        public ActionResult ApplyAttachment(IEnumerable <UploadFileModel> input)
        {
            var source             = MockData.UploadMockData.MockAttachmentModel;
            var isexistingcustomer = false;
            var model = new UploadAttachmentModel();

            model.MaxFileSize       = 1024;
            model.IsValidIdRequired = (source != null && source.Any(x => x.DocumentTypeId == 1)) && (
                /*NOT EXISTING CUSTOMER AND NOT OPTIONAL*/
                (!isexistingcustomer && !source.First(x => x.DocumentTypeId == 1).IsOptional) ||
                /*EXISTING CUSTOMER,  EXISTINGOPTON IS TRUE AND NOT OPTIONAL*/
                (isexistingcustomer && source.First(x => x.DocumentTypeId == 1).ExistingCustomerRequired&& !source.First(x => x.DocumentTypeId == 1).IsOptional)
                );

            model.IsProofOfIncomeRequired = (source != null && source.Any(x => x.DocumentTypeId == 2)) && (
                /*NOT EXISTING CUSTOMER AND NOT OPTIONAL*/
                (!isexistingcustomer && !source.First(x => x.DocumentTypeId == 2).IsOptional) ||
                /*EXISTING CUSTOMER,  EXISTINGOPTON IS TRUE AND NOT OPTIONAL*/
                (isexistingcustomer && source.First(x => x.DocumentTypeId == 2).ExistingCustomerRequired&& !source.First(x => x.DocumentTypeId == 2).IsOptional)
                );

            model.IsOtherRequired = (source != null && source.Any(x => x.DocumentTypeId == 3)) && (
                /*NOT EXISTING CUSTOMER AND NOT OPTIONAL*/
                (!isexistingcustomer && !source.First(x => x.DocumentTypeId == 3).IsOptional) ||
                /*EXISTING CUSTOMER,  EXISTINGOPTON IS TRUE AND NOT OPTIONAL*/
                (isexistingcustomer && source.First(x => x.DocumentTypeId == 3).ExistingCustomerRequired&& !source.First(x => x.DocumentTypeId == 3).IsOptional)
                );

            model.ValidIdLabel       = source.First(x => x.DocumentTypeId == 1).DocumentTypeName;
            model.ProofOfIncomeLabel = source.First(x => x.DocumentTypeId == 2).DocumentTypeName;
            model.OthersLabel        = source.First(x => x.DocumentTypeId == 3).DocumentTypeName;

            model.ValidIdList       = source.First(x => x.DocumentTypeId == 1).DocumentAttachments;
            model.ProofOfIncomeList = source.First(x => x.DocumentTypeId == 2).DocumentAttachments;
            model.OthersList        = source.First(x => x.DocumentTypeId == 3).DocumentAttachments;

            //model.ValidIdAttachment = new List<UploadDocumentDetail>();
            //model.ProofOfIncomeAttachment = new List<UploadDocumentDetail>();
            //model.OthersAttachment = new List<UploadDocumentDetail>();

            return(View(model));
        }
Example #7
0
        public async Task <IActionResult> UploadFile([FromBody] UploadAttachmentModel model)
        {
            try
            {
                if (_fileService is LocalFileService localFileService)
                {
                    if (await CanAccessDocument(model.DocumentId, true))
                    {
                        await localFileService.UploadFileToDocument(model);

                        return(Ok());
                    }

                    return(PermissionError());
                }

                return(BadRequest(
                           "MyPortal is currently configured to use a 3rd party file provider. Please use LinkHostedFile endpoint instead."));
            }
            catch (Exception e)
            {
                return(HandleException(e));
            }
        }
Example #8
0
 public abstract Task <string> UploadFile(UploadAttachmentModel upload);