public int UpdateDocumentMaterial(DocumentVersionViewModel model, int LoggedInUserId, int LoggedInOrganizationId) { DocumentVersion docVersion = Mapper.Map <DocumentVersionViewModel, DocumentVersion>(model); docVersion = GetSingle(model.DocumentVersionID, LoggedInUserId, LoggedInOrganizationId); docVersion.FileName = model.FileName; docVersion.FilePath = model.FilePath; base.Update(docVersion); this._unitOfWork.Save(); return(docVersion.DocumentVersionID); }
private void CopyFile(DocumentViewModel document, DocumentVersionViewModel documentVersion, string sourceFileName, string destinationFolder) { var fileToCopy = document.Title + " - V" + documentVersion.VersionNumber + Path.GetExtension(sourceFileName); var destinationFileName = Path.Combine(destinationFolder, fileToCopy); if (File.Exists(sourceFileName)) { File.Copy(sourceFileName, destinationFileName, overwrite: true); } Process.Start(destinationFolder); }
public async Task <HttpResponseMessage> SaveMaterial() { DocumentVersionViewModel model = new DocumentVersionViewModel(); // Send OK Response along with saved file names to the client. var provider = await Request.Content.ReadAsMultipartAsync <InMemoryMultipartFormDataStreamProvider>(new InMemoryMultipartFormDataStreamProvider()); //access form data NameValueCollection formData = provider.FormData; model.DocumentVersionID = Convert.ToInt32(formData["DocumentVersionID"]); //access files IList <HttpContent> files = provider.Files; if (files != null && files.Count > 0) { HttpContent file1 = files[0]; var thisFileName = file1.Headers.ContentDisposition.FileName.Trim('\"'); model.FileName = thisFileName; string filename = String.Empty; Stream input = await file1.ReadAsStreamAsync(); string directoryName = String.Empty; string URL = String.Empty; var path = HttpRuntime.AppDomainAppPath; directoryName = System.IO.Path.Combine(path, "Documents"); filename = System.IO.Path.Combine(directoryName, thisFileName); string ext = Path.GetExtension(filename); string guid = Guid.NewGuid().ToString(); //model.FileExtension = ext; filename = System.IO.Path.Combine(directoryName, guid + ext); //Deletion exists file if (File.Exists(filename)) { File.Delete(filename); } Directory.CreateDirectory(@directoryName); using (Stream file = File.Create(filename)) { input.CopyTo(file); //close file file.Close(); } model.FilePath = "~/Documents/" + guid + ext; } this._IDocumentVersionRepository.UpdateDocumentMaterial(model, base.UserId, base.OrganizationId); var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }
public void UploadDocument_WhenCalled_UploadsDocumentsUsingFileHelper() { var document = new DocumentViewModel() { Id = 1 }; var documentVersion = new DocumentVersionViewModel(document.Id); documentVersionsWindowViewModel.SelectedDocument = document; documentVersionsWindowViewModel.SelectedDocumentVersion = documentVersion; documentVersionsWindowViewModel.UploadDocument(); stubFileHelper.Verify(fh => fh.UpdateFiles(documentVersionsWindowViewModel.SelectedDocument, documentVersionsWindowViewModel.SelectedDocumentVersion)); }
public void UpdateFiles(DocumentViewModel document, DocumentVersionViewModel documentVersion) { var(publicPDF, publicEditable, privateCurrentPDF, privateCurrentEditable, privateObselete) = GetUploadPaths(document); DeleteFile(document, publicPDF); CopyFile(document, documentVersion, documentVersion.Location_PDF, publicPDF); MoveFile(document, privateCurrentPDF, privateObselete); CopyFile(document, documentVersion, documentVersion.Location_PDF, privateCurrentPDF); MoveFile(document, privateCurrentEditable, privateObselete); CopyFile(document, documentVersion, documentVersion.Location_Editable, privateCurrentEditable); if (document.Type == DocumentType.Form) { DeleteFile(document, publicEditable); CopyFile(document, documentVersion, documentVersion.Location_Editable, publicEditable); } }