コード例 #1
0
        private IPdfDocumentAction FindPdfDocumentAction(string documentId)
        {
            IPdfDocumentAction action = DocumentActions[documentId] as IPdfDocumentAction;

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

            return(action);
        }
コード例 #2
0
        public HttpResponseMessage Download([FromUri] string documentId, [FromBody] JObject data)
        {
            try
            {
                Contract.NotEmpty(documentId, "帳票ID");
                Contract.NotNull(data, "データ");

                if (data["data"] != null)
                {
                    data = JObject.Parse(data["data"].ToString());
                }

                IPdfDocumentAction action = FindPdfDocumentAction(documentId);

                if (action == null)
                {
                    return(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, Resources.Messages.NotFoundData));
                }

                action.Identity = this.RequestContext.Principal.Identity;

                ValidationResult validationResult = action.ValidateParamters(data);

                if (!validationResult.IsValid)
                {
                    return(this.Request.CreateResponse(HttpStatusCode.BadRequest, validationResult.CreateWebApiErrorResponse()));
                }

                IEnumerable <DocumentData> documentData = action.ConvertToDocumentData(data);
                PdfDocument pdfDoc = new PdfDocument();
                byte[]      result = pdfDoc.CreatePdf(documentData.ToArray());


                MemoryStream stream = new MemoryStream(result);
                return(this.Request.CreateFileResponse(HttpStatusCode.OK, stream, documentId + ".pdf", "application/pdf"));
            }
            catch (Exception ex)
            {
                WriteErrorLog(ex);
                return(this.Request.CreateFileDownloadErrorResponse(HttpStatusCode.Redirect, Resources.Messages.PdfServiceError, string.Empty));
            }
        }