public async Task <ActionResult> ExportToPDFFile(AdvancedSearchViewModel advancedSearchViewModel) { if (advancedSearchViewModel.AccountID == 0) { advancedSearchViewModel.AccountID = this.Identity.ToAccountID(); } advancedSearchViewModel.PageNumber = 1; ExportSearchResponse exportResponse = await advancedSearchService.ExportSearchToPDFAsync(new ExportSearchRequest() { SearchViewModel = advancedSearchViewModel, FileType = "PDF", 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)); }
/// <summary> /// Exports the results. /// </summary> /// <param name="exportViewModel">The export view model.</param> /// <returns></returns> public async Task <ActionResult> ExportResults(AdvancedSearchExportViewModel exportViewModel) { var viewModel = (AdvancedSearchViewModel)Session["AdvancedSearchVM"]; if (viewModel != null) { viewModel.PageNumber = 1; } int accountID = this.Identity.ToAccountID(); string accountsids = System.Configuration.ConfigurationManager.AppSettings["Excluded_Accounts"].ToString(); bool accountFound = accountsids.Contains(accountID.ToString()); if (accountFound) { throw new UnsupportedOperationException("[| You do not have permission to perform this operation.|]"); } ExportSearchResponse exportResponse = await advancedSearchService.ExportSearchAsync(new ExportSearchRequest() { SearchViewModel = viewModel, DownloadType = exportViewModel.DownloadType, AccountId = accountID, DateFormat = this.Identity.ToDateFormat(), TimeZone = this.Identity.ToTimeZone(), SelectedFields = exportViewModel.SelectedFields, SelectedContactIds = exportViewModel.SelectedContactIds }); string fileKey = Guid.NewGuid().ToString(); bool result = cachingService.StoreTemporaryFile(fileKey, exportResponse.byteArray); //FormData data = formService.GetFormData(9849); //JavaScriptSerializer js = new JavaScriptSerializer(); //var deserializedForm = js.Deserialize<Dictionary<string, Dictionary<string, string>>>(data.SubmittedData); //var model = (Dictionary<string, Dictionary<string, string>>)deserializedForm; //PDFGenerator pdfGen = new PDFGenerator(); //byte[] bytes = pdfGen.GenerateFormSubmissionPDF(model, "LOCALHOST", "TEST FORM", "https://images.smarttouchinteractive.com/2039/ai/011b2149-27c1-4916-9605-72b25ac8235f.jpg"); //bool result1 = cachingService.StoreTemporaryFile("64576457", bytes); 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); }