Example #1
0
        public async Task <IActionResult> Create(
            [FromQuery] string templateId,
            [FromQuery] string templateVersion,
            [FromQuery] string key)
        {
            DocumentCreate create = null;

            if (!string.IsNullOrEmpty(key))
            {
                create = _documentEncoder.Decode(key);
            }
            else if (!string.IsNullOrEmpty(templateId) && !string.IsNullOrEmpty(templateVersion))
            {
                create = GetDocumentCreate(templateId, templateVersion);
            }
            else
            {
                return(BadRequest());
            }

            if (Request.ContentType == "text/plain")
            {
                var document = await _documentService.CreateTextDocumentAsync(create);

                return(Content(document.Body));
            }
            else if (Request.ContentType == "application/vnd+document+key")
            {
                var document = _documentEncoder.Encode(create);
                return(Content(document));
            }
            else if (Request.ContentType == "application/vnd+document+html")
            {
                var document = await _documentService.CreateHtmlDocumentAsync(create);

                return(Ok(document));
            }
            else if (Request.ContentType == "application/vnd+document+json")
            {
                var document = await _documentService.CreateSerializableDocumentAsync(create);

                return(Ok(document));
            }
            else
            {
                var document = await _documentService.CreateHtmlDocumentAsync(create);

                var html = @"
                    <html>
                        <head>
                            <style type=""text/css"">" + document.Css + @"</style>
                        </head>
                        <body>" + string.Join(string.Empty, document.Pages) + @"</body>
                    </html>";

                Response.ContentType = "text/html; charset=utf-8";

                return(Content(html));
            }
        }
Example #2
0
        public static DocumentCreate Decode(this IDocumentEncoder documentEncoder, string encodedDocument)
        {
            Guid nonce;
            var  result = documentEncoder.Decode(encodedDocument, out nonce);

            return(result);
        }