Example #1
0
        public async Task <IActionResult> Export(
            [FromServices] BaseHandler json, [FromServices] XlsHandler xls, [FromServices] HtmlHandler html, [FromQuery] string format
            )
        {
            try
            {
                IActionResult file = null;
                switch (format.ToLower())
                {
                case "xlsx":
                case "xls":
                    file = this.File(await xls.GetExportAsync(this.UserId), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                    break;

                case "html":
                    file = this.File(await html.GetExportAsync(this.UserId), "text/html");
                    break;

                default:
                    file = this.File(await json.GetExportAsync(this.UserId), "application/json");
                    break;
                }
                return(file);
            }
            catch (Exception e)
            {
                return(this.Ok(e));
            }
        }