/// <summary> Gets the given request. </summary> /// <param name="request"> The request. </param> /// <returns> A Task<object> </returns> public async Task <object> Get(GetReportDownload request) { if (string.IsNullOrEmpty(request.IncludeItemTypes)) { return(null); } var headers = new Dictionary <string, string>(); string fileExtension = "csv"; string contentType = "text/plain;charset='utf-8'"; switch (request.ExportType) { case ReportExportType.CSV: break; case ReportExportType.Excel: contentType = "application/vnd.ms-excel"; fileExtension = "xls"; break; } var filename = "ReportExport." + fileExtension; headers["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename); headers["Content-Encoding"] = "UTF-8"; ReportViewType reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); ReportBuilder reportBuilder = new ReportBuilder(_libraryManager); QueryResult <BaseItem> queryResult = await GetQueryResult(request).ConfigureAwait(false); ReportResult reportResult = reportBuilder.GetReportResult(queryResult.Items, reportRowType, request); reportResult.TotalRecordCount = queryResult.TotalRecordCount; string result = string.Empty; switch (request.ExportType) { case ReportExportType.CSV: result = new ReportExport().ExportToCsv(reportResult); break; case ReportExportType.Excel: result = new ReportExport().ExportToExcel(reportResult); break; } object ro = ResultFactory.GetResult(result, contentType, headers); return(ro); }
/// <summary> Gets the given request. </summary> /// <param name="request"> The request. </param> /// <returns> A Task<object> </returns> public async Task<object> Get(GetReportDownload request) { if (string.IsNullOrEmpty(request.IncludeItemTypes)) return null; request.DisplayType = "Export"; ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView); var headers = new Dictionary<string, string>(); string fileExtension = "csv"; string contentType = "text/plain;charset='utf-8'"; switch (request.ExportType) { case ReportExportType.CSV: break; case ReportExportType.Excel: contentType = "application/vnd.ms-excel"; fileExtension = "xls"; break; } var filename = "ReportExport." + fileExtension; headers["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename); headers["Content-Encoding"] = "UTF-8"; ReportResult result = null; switch (reportViewType) { case ReportViewType.ReportStatistics: case ReportViewType.ReportData: ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); ReportBuilder dataBuilder = new ReportBuilder(_libraryManager); QueryResult<BaseItem> queryResult = await GetQueryResult(request).ConfigureAwait(false); result = dataBuilder.GetResult(queryResult.Items, request); result.TotalRecordCount = queryResult.TotalRecordCount; break; case ReportViewType.ReportActivities: result = await GetReportActivities(request).ConfigureAwait(false); break; } string returnResult = string.Empty; switch (request.ExportType) { case ReportExportType.CSV: returnResult = new ReportExport().ExportToCsv(result); break; case ReportExportType.Excel: returnResult = new ReportExport().ExportToExcel(result); break; } object ro = ResultFactory.GetResult(returnResult, contentType, headers); return ro; }
/// <summary> Gets the given request. </summary> /// <param name="request"> The request. </param> /// <returns> A Task<object> </returns> public async Task <object> Get(GetReportDownload request) { if (string.IsNullOrEmpty(request.IncludeItemTypes)) { return(null); } request.DisplayType = "Export"; ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView); var headers = new Dictionary <string, string>(); string fileExtension = "csv"; string contentType = "text/plain;charset='utf-8'"; switch (request.ExportType) { case ReportExportType.CSV: break; case ReportExportType.Excel: contentType = "application/vnd.ms-excel"; fileExtension = "xls"; break; } var filename = "ReportExport." + fileExtension; headers["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename); headers["Content-Encoding"] = "UTF-8"; var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null; ReportResult result = null; switch (reportViewType) { case ReportViewType.ReportStatistics: case ReportViewType.ReportData: ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes); ReportBuilder dataBuilder = new ReportBuilder(_libraryManager); QueryResult <BaseItem> queryResult = await GetQueryResult(request, user).ConfigureAwait(false); result = dataBuilder.GetResult(queryResult.Items, request); result.TotalRecordCount = queryResult.TotalRecordCount; break; case ReportViewType.ReportActivities: result = GetReportActivities(request); break; } string returnResult = string.Empty; switch (request.ExportType) { case ReportExportType.CSV: returnResult = new ReportExport().ExportToCsv(result); break; case ReportExportType.Excel: returnResult = new ReportExport().ExportToExcel(result); break; } return(ResultFactory.GetResult(returnResult, contentType, headers)); }