public async Task <object> Export( [FromQuery(Name = "$filter")] string filter = "", [FromQuery(Name = "$orderby")] string orderBy = "", [FromQuery(Name = "$top")] int top = 0, [FromQuery(Name = "$skip")] int skip = 0, string fileType = "") { try { //determine top value int maxExport = int.Parse(config["App:MaxExportRecords"]); top = top > maxExport | top == 0 ? maxExport : top; //if $top is greater than max or equal to 0 use max export value ODataHelper <AuditLog> oData = new ODataHelper <AuditLog>(); string queryString = HttpContext.Request.QueryString.Value; oData.Parse(queryString); oData.Top = top; var auditLogsJson = base.GetMany(oData: oData); string csvString = manager.GetAuditLogs(auditLogsJson.Items.ToArray()); var csvFile = File(new System.Text.UTF8Encoding().GetBytes(csvString), "text/csv", "AuditLogs.csv"); switch (fileType.ToLower()) { case "csv": return(csvFile); case "zip": var zippedFile = manager.ZipCsv(csvFile); const string contentType = "application/zip"; HttpContext.Response.ContentType = contentType; var zipFile = new FileContentResult(zippedFile.ToArray(), contentType) { FileDownloadName = "AuditLogs.zip" }; return(zipFile); case "json": return(auditLogsJson); } return(csvFile); } catch (Exception ex) { ModelState.AddModelError("Export", ex.Message); return(ex.GetActionResult()); } }