public async Task <object> Export( [FromQuery(Name = "$filter")] string filter = "", [FromQuery(Name = "$orderby")] string orderBy = "", [FromQuery(Name = "$top")] int top = 100, [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 <Job> oData = new ODataHelper <Job>(); string queryString = HttpContext.Request.QueryString.Value; oData.Parse(queryString); oData.Top = top; var jobsJson = base.GetMany(oData: oData); string csvString = jobManager.GetCsv(jobsJson.Items.ToArray()); var csvFile = File(new System.Text.UTF8Encoding().GetBytes(csvString), "text/csv", "Jobs.csv"); switch (fileType.ToLower()) { case "csv": return(csvFile); case "zip": var zippedFile = jobManager.ZipCsv(csvFile); const string contentType = "application/zip"; HttpContext.Response.ContentType = contentType; var zipFile = new FileContentResult(zippedFile.ToArray(), contentType) { FileDownloadName = "Jobs.zip" }; return(zipFile); case "json": return(jobsJson); } return(csvFile); } catch (Exception ex) { ModelState.AddModelError("Export", ex.Message); return(ex.GetActionResult()); } }
public PaginatedList <ProcessExecutionViewModel> View( [FromQuery(Name = "$filter")] string filter = "", [FromQuery(Name = "$orderby")] string orderBy = "", [FromQuery(Name = "$top")] int top = 100, [FromQuery(Name = "$skip")] int skip = 0 ) { ODataHelper <ProcessExecutionViewModel> oData = new ODataHelper <ProcessExecutionViewModel>(); string queryString = ""; if (HttpContext != null && HttpContext.Request != null && HttpContext.Request.QueryString != null && HttpContext.Request.QueryString.HasValue) { queryString = HttpContext.Request.QueryString.Value; } oData.Parse(queryString); Guid parentguid = Guid.Empty; var newNode = oData.ParseOrderByQuerry(queryString); if (newNode == null) { newNode = new OrderByNode <ProcessExecutionViewModel>(); } Predicate <ProcessExecutionViewModel> predicate = null; if (oData != null && oData.Filter != null) { predicate = new Predicate <ProcessExecutionViewModel>(oData.Filter); } int take = (oData?.Top == null || oData?.Top == 0) ? 100 : oData.Top; return(processExecutionLogManager.GetProcessAndAgentNames(predicate, newNode.PropertyName, newNode.Direction, oData.Skip, take)); }