public async Task <ActionResult> ExportToCSVFile(AdvancedSearchViewModel advancedSearchViewModel) { if (advancedSearchViewModel.AccountID == 0) { advancedSearchViewModel.AccountID = this.Identity.ToAccountID(); } advancedSearchViewModel.PageNumber = 1; ExportSearchResponse exportResponse = await advancedSearchService.ExportSearchToCSVAsync(new ExportSearchRequest() { SearchViewModel = advancedSearchViewModel, FileType = "CSV", DateFormat = this.Identity.ToDateFormat(), TimeZone = this.Identity.ToTimeZone() }); string fileKey = Guid.NewGuid().ToString(); bool result = cachingService.StoreTemporaryFile(fileKey, exportResponse.byteArray); Logger.Current.Informational("Did temporary file stored in cache : " + result.ToString()); return(Json(new { success = true, fileKey = fileKey, fileName = exportResponse.FileName }, JsonRequestBehavior.AllowGet)); }
public async Task <HttpResponseMessage> ExportToCSVFile(AdvancedSearchViewModel viewModel) { if (viewModel.AccountID == 0) { viewModel.AccountID = this.AccountId; } ExportSearchResponse response = await advancedSearchService.ExportSearchToCSVAsync( new ExportSearchRequest() { SearchViewModel = viewModel }); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); Stream stream = new MemoryStream(response.byteArray); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = response.FileName }; return(result); }