예제 #1
0
        public async Task <IActionResult> Upload(string englishDesc, string frenchDesc, IFormFile file)
        {
            var documentUpload = await documentRepository.GetDocuments();

            // var doc = await

            //   i//f (poster == null)
            //  return NotFound();

            if (file == null)
            {
                return(BadRequest("Null Document File"));
            }
            if (file.Length == 0)
            {
                return(BadRequest("Empty Document File"));
            }
            if (file.Length > documentSettings.MaxBytes)
            {
                return(BadRequest("Maximum file size exceeded"));
            }
            if (!documentSettings.IsSupported(file.FileName))
            {
                return(BadRequest("File type is invalid"));
            }


            var uploadsFolderPath = Path.Combine(host.WebRootPath, "documentUploads");

            if (!Directory.Exists(uploadsFolderPath))
            {
                Directory.CreateDirectory(uploadsFolderPath);
            }

            var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);

            var filePath = Path.Combine(uploadsFolderPath, fileName);

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }

            var document = new Document {
                DocumentFileName = fileName, EnglishDesc = englishDesc, FrenchDesc = frenchDesc
            };

            //  context.Documents.Add(document);
            // context.Documents.Add(document);
            documentRepository.Add(document);
            await unitOfWork.CompleteAsync();

            return(Ok(mapper.Map <Document, DocumentResource>(document)));
        }
예제 #2
0
        public async Task <IActionResult> Upload(int projectId, IFormFile file)
        {
            var project = await _unitOfWork.Projects.GetAsync(projectId);

            if (project == null)
            {
                return(NotFound());
            }

            if (file == null)
            {
                return(BadRequest("The file can not be null"));
            }
            if (file.Length <= 0)
            {
                return(BadRequest("The file cannot be empty"));
            }
            if (file.Length > _documentSettings.MaxBytes)
            {
                return(BadRequest("The max file size was exceeded"));
            }
            if (!_documentSettings.IsSupported(file.FileName))
            {
                return(BadRequest("Invalid file type"));
            }

            var uploadsFolderPath = Path.Combine(_host.WebRootPath, "uploads/payments");

            if (!Directory.Exists(uploadsFolderPath))
            {
                Directory.CreateDirectory(uploadsFolderPath);
            }

            var filePath = Path.Combine(uploadsFolderPath, file.FileName);

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }

            var document = new Document {
                FileName = file.FileName
            };

            project.Documents.Add(document);
            await _unitOfWork.CompleteAsync();

            return(Ok(_mapper.Map <Document, DocumentResource>(document)));
        }
예제 #3
0
        public IActionResult Upload(int Id, IFormFile file)
        {
            var expense = _uow.Expenses.GetById(Id);

            if (expense == null)
            {
                return(NotFound());
            }

            if (file == null)
            {
                return(BadRequest("File not valid"));
            }
            if (file.Length == 0)
            {
                return(BadRequest("Empty File"));
            }
            if (file.Length > _options.MaxBytes)
            {
                return(BadRequest("File exceeded 10 MB size!"));
            }

            if (!_options.IsSupported(file.FileName))
            {
                return(BadRequest("Invalid File Type"));
            }
            var uploadsFolder = Path.Combine(_host.WebRootPath, "uploads");

            if (!Directory.Exists(uploadsFolder))
            {
                Directory.CreateDirectory(uploadsFolder);
            }

            var fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
            var filepath = Path.Combine(uploadsFolder, fileName);

            using (var stream = new FileStream(filepath, FileMode.Create))
            {
                file.CopyTo(stream);
            }

            var doc = new Documents {
                DocName = fileName
            };

            expense.Docs.Add(doc);
            _uow.Commit();
            return(Ok(doc));
        }
예제 #4
0
        public async Task <IActionResult> UploadDocument(int documentPartageId, IFormFile file)
        {
            if (file == null)
            {
                return(BadRequest("No File"));
            }
            if (file.Length == 0)
            {
                return(BadRequest("Empty File"));
            }
            if (file.Length > _documentSettings.MaxBytes)
            {
                return(BadRequest("File Too Large"));
            }
            if (!_documentSettings.IsSupported(file.FileName))
            {
                return(BadRequest("Invalid Type File"));
            }

            return(Ok(await _appService.UploadDocumentFile(documentPartageId, file)));
        }