Ejemplo n.º 1
0
        public async Task <IActionResult> GenerateDocument(string uxoid)
        {
            var contentType = "APPLICATION/octet-stream";
            var uxo         = await _uxoService.FetchUXO(uxoid);

            if (uxo == null)
            {
                return(NotFound(uxoid));
            }

            var fileBytes = await _documentService.CreateDocument(uxo);

            if (fileBytes == null || fileBytes.Length == 0)
            {
                return(NoContent());
            }

            var fileName = $"UXO-{DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mmZ")}.docx";

            var contentDisposition = new ContentDisposition()
            {
                FileName = fileName,
                Inline   = false
            };

            Response.Headers.Add("Content-Disposition", contentDisposition.ToString());

            return(File(fileBytes, contentType));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> GenerateDocument(string uxoid)
        {
            var uxo = await _uxoService.FetchUXO(uxoid);

            if (uxo == null)
            {
                return(NotFound(new ErrorResponse()
                {
                    StatusCode = (int)HttpStatusCode.NotFound, Message = $"Unable to retrieve item '{uxoid}'"
                }));
            }

            var fileBytes = await _documentService.CreateDocument(uxo);

            if (fileBytes == null || fileBytes.Length == 0)
            {
                return(StatusCode(
                           (int)HttpStatusCode.InternalServerError,
                           new ErrorResponse()
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError, Message = "Unable to generate the document."
                }
                           ));
            }

            var fileName = $"UXO-{DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mmZ")}.docx";

            var contentDisposition = new ContentDisposition()
            {
                FileName = fileName,
                Inline   = false
            };

            Response.Headers.Add("Content-Disposition", contentDisposition.ToString());

            var contentType = "APPLICATION/octet-stream";

            return(File(fileBytes, contentType));
        }