public IActionResult AddDocument(AddDocumentRequestVm addDocumentRequestVm)
        {
            var uploadResult = fileUploadHelper.UploadFile(environment.WebRootPath, CurrentUser.UserId, addDocumentRequestVm.Directory,
                                                           addDocumentRequestVm.Version, addDocumentRequestVm.File);

            if (uploadResult.Item1 == HttpStatusCode.Conflict)
            {
                return(Conflict());
            }

            if (uploadResult.Item1 == HttpStatusCode.InternalServerError)
            {
                return(StatusCode(500));
            }

            var filePath   = uploadResult.Item2;
            var documentDm = new DocumentDm
            {
                DocumentName    = addDocumentRequestVm.File.FileName,
                DocumentOwnerId = CurrentUser.UserId,
                DocumentVersion = addDocumentRequestVm.Version,
                DocumentPath    = filePath
            };

            var addedDocument = documentManager.Add(documentDm);

            return(Ok(addedDocument));
        }
Esempio n. 2
0
        public DocumentDm Add(DocumentDm documentDm)
        {
            var document = documentRepository.Add(new Document
            {
                DocumentId      = documentDm.DocumentId,
                DocumentName    = documentDm.DocumentName,
                DocumentPath    = documentDm.DocumentPath,
                DocumentVersion = documentDm.DocumentVersion,
                DocumentOwnerId = documentDm.DocumentOwnerId,
                CreatedOn       = documentDm.CreatedOn,
                ModifiedOn      = documentDm.ModifiedOn
            });

            if (document == null)
            {
                return(null);
            }

            return(new DocumentDm
            {
                DocumentId = document.DocumentId,
                DocumentName = document.DocumentName,
                DocumentPath = document.DocumentPath,
                DocumentVersion = document.DocumentVersion,
                DocumentOwnerId = document.DocumentOwnerId,
                CreatedOn = document.CreatedOn,
                ModifiedOn = document.ModifiedOn
            });
        }