Ejemplo n.º 1
0
        public async Task <IActionResult> Run(RunParams runParams)
        {
            string documentId = runParams.DocumentId ?? DefaultDocumentId;

            await SetRunPrerequisites(documentId);

            string            attachmentName = runParams.AttachmentName;
            string            contentType    = runParams.ContentType;
            AttachmentWrapper attachment;

            if (runParams.Attachment == null)
            {
                attachment = new LocalFileAttachmentWrapper(DefaultFilePath);
            }
            else
            {
                FileValidator.Check(runParams.Attachment);
                attachment = new FormFileAttachmentWrapper(runParams.Attachment);
            }

            #region Demo
            using (IDocumentSession session = DocumentStoreHolder.Store.OpenSession())
                #region Step_1
                using (Stream stream = attachment.OpenStream())
                #endregion
                {
                    #region Step_2
                    session.Advanced.Attachments.Store(documentId, attachmentName, stream, contentType);
                    #endregion

                    #region Step_3
                    session.SaveChanges();
                    #endregion
                }
            #endregion

            return(Ok($"Attachment {attachmentName} was stored successfully on document {documentId}"));
        }