public string CustomerScheduleExport(CustomerScheduleModelFilter filter, long userId) { var fileName = GetExportableFileName("CustomerSchedule"); var csvFilePath = Path.Combine(ExportableMediaLocation.PhysicalPath, fileName); var dataGen = new ExportableDataGenerator <EventCustomerScheduleModel, CustomerScheduleModelFilter>(_eventCustomerReportingService.GetCustomerScheduleModel, Logger); var model = dataGen.GetData(filter); var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <CustomerScheduleModel>(); var csvStringBuilder = _customerScheduleCsvHelper.GetPatientScheduledReport(model.Collection, exporter); var request = new GenericReportRequest { CsvFilePath = csvFilePath, Model = csvStringBuilder.ToString() }; var isGenerated = _baseReportService.GetResponse(request); if (!isGenerated) { return("CSV File Export failed!"); } return(_baseReportService.DownloadZipFile(ExportableMediaLocation, fileName, userId, Logger)); }
public bool GenerateCsv <T>(string csvFilePath, CSVExporter <T> exporter, IEnumerable <T> modelData, string filterCriteria = "", bool skipHeader = false) { var csvStringBuilder = new StringBuilder(); var sanitizer = new CSVSanitizer(); if (!string.IsNullOrEmpty(filterCriteria)) { csvStringBuilder.Append(sanitizer.EscapeString(filterCriteria) + Environment.NewLine + Environment.NewLine); } if (!skipHeader) { csvStringBuilder.Append(exporter.Header + Environment.NewLine); } foreach (string line in exporter.ExportObjects(modelData)) { csvStringBuilder.Append(line + Environment.NewLine); } var request = new GenericReportRequest { Model = csvStringBuilder.ToString(), CsvFilePath = csvFilePath }; var isGenerated = _baseReportService.GetResponse(request, skipHeader); return(isGenerated); }
private string WriteCsv <T>(string fileName, CSVExporter <T> exporter, IEnumerable <T> modelData, string queue, string channel) { var csvFilePath = _tempMediaLocation.PhysicalPath + fileName; //using (var streamWriter = new StreamWriter(csvFilePath, false)) //{ var csvStringBuilder = new StringBuilder(); csvStringBuilder.Append(exporter.Header + Environment.NewLine); foreach (string line in exporter.ExportObjects(modelData)) { csvStringBuilder.Append(line + Environment.NewLine); } // streamWriter.Close(); //} var request = new GenericReportRequest { Model = csvStringBuilder.ToString(), CsvFilePath = csvFilePath }; var isGenerated = GetResponse(request, queue, channel); if (!isGenerated) { return("CSV File Export failed!"); } DownloadZipFile(_tempMediaLocation, fileName); return("CSV File Export was succesful!"); }
protected void ProcessReports(GenericReportRequest request) { using (var streamWriter = new StreamWriter(request.CsvFilePath, false)) { streamWriter.Write(request.Model); streamWriter.Close(); } }
public bool GetResponse(GenericReportRequest request, bool append = false) { using (var streamWriter = new StreamWriter(request.CsvFilePath, append)) { streamWriter.Write(request.Model); streamWriter.Close(); } return(true); }
private string WriteCsvHospitalPartnerEvent(string fileName, IEnumerable <HospitalPartnerEventViewModel> modelData) { var csvFilePath = _tempMediaLocation.PhysicalPath + fileName; // using (var streamWriter = new StreamWriter(csvFilePath, false)) //{ var csvStringBuilder = new StringBuilder(); var members = (typeof(HospitalPartnerEventViewModel)).GetMembers(); var header = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <NotesViewModel>)) { continue; } } else { continue; } string propertyName = memberInfo.Name; bool isHidden = false; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is DisplayNameAttribute) { propertyName = (attribute as DisplayNameAttribute).DisplayName; } } } if (isHidden) { continue; } header.Add(propertyName); } header.Add("Notes"); csvStringBuilder.Append(string.Join(",", header.ToArray()) + Environment.NewLine); var sanitizer = new CSVSanitizer(); foreach (var model in modelData) { var values = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <NotesViewModel>)) { continue; } } else { continue; } bool isHidden = false; FormatAttribute formatter = null; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is FormatAttribute) { formatter = (FormatAttribute)attribute; } } } if (isHidden) { continue; } var obj = propInfo.GetValue(model, null); if (obj == null) { values.Add(string.Empty); } else if (formatter != null) { values.Add(formatter.ToString(obj)); } else { values.Add(sanitizer.EscapeString(obj.ToString())); } } if (model.Notes != null && model.Notes.Count() > 0) { var notesString = string.Empty; foreach (var notesViewModel in model.Notes) { notesString += "Updated On: " + (notesViewModel.EnteredOn.HasValue ? notesViewModel.EnteredOn.Value.ToShortDateString() : string.Empty) + "\n"; notesString += "Updated By: " + notesViewModel.CreatedByUser + "\n"; notesString += "Notes: " + notesViewModel.Note + "\n\n"; } values.Add(sanitizer.EscapeString(notesString)); } else { values.Add(string.Empty); } csvStringBuilder.Append(string.Join(",", values.ToArray()) + Environment.NewLine); } // streamWriter.Close(); //} var request = new GenericReportRequest { CsvFilePath = csvFilePath, Model = csvStringBuilder.ToString() }; var isGenerated = GetResponse(request, RequestSubcriberChannelNames.GenerateHospitalPartnerEventReportQueue, RequestSubcriberChannelNames.GenerateHospitalPartnerEventReportChannel); if (!isGenerated) { return("CSV File Export failed!"); } DownloadZipFile(_tempMediaLocation, fileName); return("CSV File Export was succesful!"); }
//private string WriteCsv<T>(string fileName, CSVExporter<T> exporter, IEnumerable<T> modelData) //{ // var csvFilePath = _tempMediaLocation.PhysicalPath + fileName; // using (var streamWriter = new StreamWriter(csvFilePath, false)) // { // streamWriter.Write(exporter.Header + Environment.NewLine); // foreach (string line in exporter.ExportObjects(modelData)) // { // streamWriter.Write(line + Environment.NewLine); // } // streamWriter.Close(); // } // DownloadZipFile(_tempMediaLocation, fileName); // return "CSV File Export was succesful!"; //} private string WriteCsvHospitalPartnerCustomer(string fileName, IEnumerable <HospitalPartnerCustomerViewModel> modelData) { var csvFilePath = _tempMediaLocation.PhysicalPath + fileName; //using (var streamWriter = new StreamWriter(csvFilePath, false)) //{ var csvStringBuilder = new StringBuilder(); var members = (typeof(HospitalPartnerCustomerViewModel)).GetMembers(); var header = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <OrderedPair <long, string> >) || propInfo.PropertyType == typeof(IEnumerable <HospitalPartnerCustomerActivityViewModel>)) { continue; } } else { continue; } string propertyName = memberInfo.Name; bool isHidden = false; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is DisplayNameAttribute) { propertyName = (attribute as DisplayNameAttribute).DisplayName; } } } if (isHidden) { continue; } header.Add(propertyName); } var tests = _testRepository.GetRecordableTests(); header.AddRange(tests.Select(test => test.Name)); header.Add("Activity"); header.Add(HealthAssessmentQuestionLabel.PrimaryCare.GetDescription()); header.Add(HealthAssessmentQuestionLabel.MammogramProstateScreening.GetDescription()); header.Add(HealthAssessmentQuestionLabel.Colonoscopy.GetDescription()); header.Add(HealthAssessmentQuestionLabel.Cancer.GetDescription()); header.Add(HealthAssessmentQuestionLabel.WeightBariatric.GetDescription()); csvStringBuilder.Append(string.Join(",", header.ToArray()) + Environment.NewLine); var sanitizer = new CSVSanitizer(); foreach (var model in modelData) { var values = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <OrderedPair <long, string> >) || propInfo.PropertyType == typeof(IEnumerable <HospitalPartnerCustomerActivityViewModel>)) { continue; } } else { continue; } bool isHidden = false; FormatAttribute formatter = null; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is FormatAttribute) { formatter = (FormatAttribute)attribute; } } } if (isHidden) { continue; } var obj = propInfo.GetValue(model, null); if (obj == null) { values.Add(string.Empty); } else if (formatter != null) { values.Add(formatter.ToString(obj)); } else { values.Add(sanitizer.EscapeString(obj.ToString())); } } foreach (var test in tests) { if (model.TestSummary != null && model.TestSummary.Count() > 0) { var summaryFinding = model.TestSummary.Where(ts => ts.FirstValue == test.Id).Select(ts => ts.SecondValue). FirstOrDefault(); values.Add(summaryFinding); } else { values.Add(string.Empty); } } if (model.Activities != null && model.Activities.Count() > 0) { var activitySummary = string.Empty; foreach (var activity in model.Activities) { activitySummary += "Status: " + activity.Status + "\n"; activitySummary += "Outcome: " + activity.Outcome + "\n"; activitySummary += "Updated On: " + activity.UpdateOn.ToShortDateString() + "\n"; activitySummary += "Updated By: " + activity.UpdatedBy + "\n"; activitySummary += "Notes: " + activity.Notes + "\n\n"; } values.Add(sanitizer.EscapeString(activitySummary)); } else { values.Add(string.Empty); } values.Add(model.PrimaryCare); values.Add(model.MammogramProstateScreening); values.Add(model.Colonoscopy); values.Add(model.Cancer); values.Add(model.WeightBariatric); csvStringBuilder.Append(string.Join(",", values.ToArray()) + Environment.NewLine); } // streamWriter.Close(); //} var request = new GenericReportRequest { CsvFilePath = csvFilePath, Model = csvStringBuilder.ToString() }; var isGenerated = GetResponse(request, RequestSubcriberChannelNames.GenerateHospitalPartnerCustomerReportQueue, RequestSubcriberChannelNames.GenerateHospitalPartnerCustomerReportChannel); if (!isGenerated) { return("CSV File Export failed!"); } DownloadZipFile(_tempMediaLocation, fileName); return("CSV File Export was succesful!"); }
private string WriteCsvForCustomerExport(string fileName, IEnumerable <CustomerExportModel> modelData, long userId) { var csvFilePath = ExportableMediaLocation.PhysicalPath + fileName; var csvStringBuilder = new StringBuilder(); var members = (typeof(CustomerExportModel)).GetMembers(); var header = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel)) { continue; } } else { continue; } string propertyName = memberInfo.Name; bool isHidden = false; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is DisplayNameAttribute) { propertyName = (attribute as DisplayNameAttribute).DisplayName; } } } if (isHidden) { continue; } header.Add(propertyName); } csvStringBuilder.Append(string.Join(",", header.ToArray()) + Environment.NewLine); var sanitizer = new CSVSanitizer(); foreach (var model in modelData) { var values = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel)) { continue; } if (propInfo.PropertyType == typeof(IEnumerable <OrderedPair <string, string> >)) { string additionalFieldsString; if (model.AdditionalFields == null || !model.AdditionalFields.Any()) { additionalFieldsString = "N/A"; } else { additionalFieldsString = model.AdditionalFields.Aggregate(string.Empty, (current, item) => current + item.FirstValue + ": " + item.SecondValue + "\n"); } values.Add(sanitizer.EscapeString(additionalFieldsString)); continue; } } else { continue; } bool isHidden = false; FormatAttribute formatter = null; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is FormatAttribute) { formatter = (FormatAttribute)attribute; } } } if (isHidden) { continue; } var obj = propInfo.GetValue(model, null); if (obj == null) { values.Add(string.Empty); } else if (formatter != null) { values.Add(formatter.ToString(obj)); } else { values.Add(sanitizer.EscapeString(obj.ToString())); } } csvStringBuilder.Append(string.Join(",", values.ToArray()) + Environment.NewLine); } var request = new GenericReportRequest { CsvFilePath = csvFilePath, Model = csvStringBuilder.ToString() }; var isGenerated = _baseReportService.GetResponse(request); if (!isGenerated) { return("CSV File Export failed!"); } return(_baseReportService.DownloadZipFile(ExportableMediaLocation, fileName, userId, Logger)); }
private string WriteCsvAppointmentBooked(string fileName, IEnumerable <AppointmentsBookedModel> modelData, long userId) { var csvFilePath = ExportableMediaLocation.PhysicalPath + fileName; var csvStringBuilder = new StringBuilder(); var members = (typeof(AppointmentsBookedModel)).GetMembers(); var header = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <OrderedPair <string, string> >)) { continue; } } else { continue; } string propertyName = memberInfo.Name; bool isHidden = false; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is DisplayNameAttribute) { propertyName = (attribute as DisplayNameAttribute).DisplayName; } } } if (isHidden) { continue; } header.Add(propertyName); } header.Add("Additional Fields"); csvStringBuilder.Append(string.Join(",", header.ToArray()) + Environment.NewLine); var sanitizer = new CSVSanitizer(); foreach (var model in modelData) { var values = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel)) { continue; } if (propInfo.PropertyType == typeof(IEnumerable <string>)) { if (model.ShippingOptions != null && model.ShippingOptions.Count() > 0) { var shippingOptions = string.Join(", \n", model.ShippingOptions.ToArray()); values.Add(sanitizer.EscapeString(shippingOptions)); } else { values.Add(string.Empty); } continue; } if (propInfo.PropertyType == typeof(IEnumerable <RescheduleApplointmentModel>) || propInfo.PropertyType == typeof(IEnumerable <OrderedPair <string, string> >)) { if (model.RescheduleInfo != null && model.RescheduleInfo.Any()) { var rescheduleInfoString = string.Empty; foreach (var rescheduleInfo in model.RescheduleInfo) { rescheduleInfoString += "Rescheduled By: " + rescheduleInfo.RescheduledBy + "\n"; rescheduleInfoString += "Reason: " + rescheduleInfo.Reason + "\n"; if (!string.IsNullOrEmpty(rescheduleInfo.SubReason)) { rescheduleInfoString += "SubReason: " + rescheduleInfo.SubReason + "\n"; } if (!string.IsNullOrEmpty(rescheduleInfo.Notes)) { rescheduleInfoString += "Notes: " + rescheduleInfo.Notes + "\n"; } rescheduleInfoString += "---------------------------\n"; } values.Add(sanitizer.EscapeString(rescheduleInfoString)); } else { values.Add("N/A"); } continue; } } else { continue; } bool isHidden = false; FormatAttribute formatter = null; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is FormatAttribute) { formatter = (FormatAttribute)attribute; } } } if (isHidden) { continue; } var obj = propInfo.GetValue(model, null); if (obj == null) { values.Add(string.Empty); } else if (memberInfo.Name == "Zip") { values.Add("=" + sanitizer.EscapeString(obj.ToString())); } else if (formatter != null) { values.Add(formatter.ToString(obj)); } else { values.Add(sanitizer.EscapeString(obj.ToString())); } } if (model.AdditionalFields != null && model.AdditionalFields.Any()) { string additionFiledString = model.AdditionalFields.Aggregate(string.Empty, (current, item) => current + item.FirstValue + ": " + item.SecondValue + "\n"); values.Add(sanitizer.EscapeString(additionFiledString)); } else { values.Add(string.Empty); } csvStringBuilder.Append(string.Join(",", values.ToArray()) + Environment.NewLine); } var request = new GenericReportRequest { CsvFilePath = csvFilePath, Model = csvStringBuilder.ToString() }; var isGenerated = _baseReportService.GetResponse(request); if (!isGenerated) { return("CSV File Export failed!"); } return(_baseReportService.DownloadZipFile(ExportableMediaLocation, fileName, userId, Logger)); }
private bool GenerateOutreachCallReportCsv(IEnumerable <HourlyOutreachCallReportModel> modelData, string csvFilePath) { var csvStringBuilder = new StringBuilder(); var members = (typeof(HourlyOutreachCallReportModel)).GetMembers(); var header = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <CallCenterNotes>)) { continue; } } else { continue; } string propertyName = memberInfo.Name; bool isHidden = false; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is DisplayNameAttribute) { propertyName = (attribute as DisplayNameAttribute).DisplayName; } } } if (isHidden) { continue; } header.Add(propertyName); } header.Add("Disposition Notes"); csvStringBuilder.Append(string.Join(",", header.ToArray()) + Environment.NewLine); var sanitizer = new CSVSanitizer(); foreach (var model in modelData) { var values = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <CallCenterNotes>)) { continue; } } else { continue; } bool isHidden = false; FormatAttribute formatter = null; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is FormatAttribute) { formatter = (FormatAttribute)attribute; } } } if (isHidden) { continue; } var obj = propInfo.GetValue(model, null); if (obj == null) { values.Add(string.Empty); } else if (formatter != null) { values.Add(formatter.ToString(obj)); } else { values.Add(sanitizer.EscapeString(obj.ToString())); } } if (model.Notes != null && model.Notes.Count() > 0) { var notesString = model.Notes.Aggregate("", (current, note) => current + ("[ " + note.DateCreated.ToShortDateString() + " ] - Notes: " + note.Notes + "\n")); values.Add(sanitizer.EscapeString(notesString)); } else { values.Add("N/A"); } csvStringBuilder.Append(string.Join(",", values.ToArray()) + Environment.NewLine); } var request = new GenericReportRequest { CsvFilePath = csvFilePath, Model = csvStringBuilder.ToString() }; var isGenerated = _baseReportService.GetResponse(request); return(isGenerated); }
private string WriteCsvGapClosureCustomer(string fileName, IEnumerable <GapsClosureModel> modelData, long userId) { var csvFilePath = ExportableMediaLocation.PhysicalPath + fileName; //using (var streamWriter = new StreamWriter(csvFilePath, false)) //{ var csvStringBuilder = new StringBuilder(); var members = (typeof(GapsClosureModel)).GetMembers(); var header = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel)) { continue; } } else { continue; } string propertyName = memberInfo.Name; bool isHidden = false; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is DisplayNameAttribute) { propertyName = (attribute as DisplayNameAttribute).DisplayName; } } } if (isHidden) { continue; } header.Add(propertyName); } //header.Add("Pre-approved Tests"); //header.Add("Test Performed"); //header.Add("Test Not Performed"); csvStringBuilder.Append(string.Join(",", header.ToArray()) + Environment.NewLine); var sanitizer = new CSVSanitizer(); foreach (var model in modelData) { var values = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <string>) || propInfo.PropertyType == typeof(IEnumerable <OrderedPair <string, string> >)) { continue; } } else { continue; } bool isHidden = false; FormatAttribute formatter = null; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is FormatAttribute) { formatter = (FormatAttribute)attribute; } } } if (isHidden) { continue; } var obj = propInfo.GetValue(model, null); if (obj == null) { values.Add(string.Empty); } else if (formatter != null) { values.Add(formatter.ToString(obj)); } else { values.Add(sanitizer.EscapeString(obj.ToString())); } } //if (model.PreApprovedTests != null && model.PreApprovedTests.Any()) //{ // var notesString = string.Join(", ", model.PreApprovedTests); // values.Add(sanitizer.EscapeString(notesString)); //} //else // values.Add(string.Empty); //if (model.ResultStatus != null && model.ResultStatus.Any()) //{ // var resultString = model.ResultStatus.Aggregate(string.Empty, (current, status) => current + status.FirstValue + " : " + status.SecondValue + " \n"); // values.Add(sanitizer.EscapeString(resultString)); //} //else // values.Add(string.Empty); //if (model.TestNotPerformed != null && model.TestNotPerformed.Any()) //{ // var resultString = model.TestNotPerformed.Aggregate(string.Empty, (current, status) => current + status.FirstValue + " : " + status.SecondValue + " \n"); // values.Add(sanitizer.EscapeString(resultString)); //} //else // values.Add(string.Empty); csvStringBuilder.Append(string.Join(",", values.ToArray()) + Environment.NewLine); } var request = new GenericReportRequest { CsvFilePath = csvFilePath, Model = csvStringBuilder.ToString() }; var isGenerated = _baseReportService.GetResponse(request); if (!isGenerated) { return("CSV File Export failed!"); } return(_baseReportService.DownloadZipFile(ExportableMediaLocation, fileName, userId, Logger)); }
private string WriteCsvCallCenterCallReport(string fileName, IEnumerable <CallCenterCallReportModel> modelData) { var csvFilePath = _tempMediaLocation.PhysicalPath + fileName; var csvStringBuilder = new StringBuilder(); var members = (typeof(CallCenterCallReportModel)).GetMembers(); var header = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <CallCenterNotes>)) { continue; } } else { continue; } string propertyName = memberInfo.Name; bool isHidden = false; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is DisplayNameAttribute) { propertyName = (attribute as DisplayNameAttribute).DisplayName; } } } if (isHidden) { continue; } header.Add(propertyName); } header.Add("Disposition Notes"); csvStringBuilder.Append(string.Join(",", header.ToArray()) + Environment.NewLine); var sanitizer = new CSVSanitizer(); foreach (var model in modelData) { var values = new List <string>(); foreach (var memberInfo in members) { if (memberInfo.MemberType != MemberTypes.Property) { continue; } var propInfo = (memberInfo as PropertyInfo); if (propInfo != null) { if (propInfo.PropertyType == typeof(FeedbackMessageModel) || propInfo.PropertyType == typeof(IEnumerable <CallCenterNotes>)) { continue; } } else { continue; } bool isHidden = false; FormatAttribute formatter = null; var attributes = propInfo.GetCustomAttributes(false); if (!attributes.IsNullOrEmpty()) { foreach (var attribute in attributes) { if (attribute is HiddenAttribute) { isHidden = true; break; } if (attribute is FormatAttribute) { formatter = (FormatAttribute)attribute; } } } if (isHidden) { continue; } var obj = propInfo.GetValue(model, null); if (obj == null) { values.Add(string.Empty); } else if (formatter != null) { values.Add(formatter.ToString(obj)); } else { values.Add(sanitizer.EscapeString(obj.ToString())); } } if (model.Notes != null && model.Notes.Count() > 0) { var notesString = model.Notes.Aggregate("", (current, note) => current + ("[ " + note.DateCreated.ToShortDateString() + " ] - Notes: " + note.Notes + "\n")); values.Add(sanitizer.EscapeString(notesString)); } else { values.Add("N/A"); } csvStringBuilder.Append(string.Join(",", values.ToArray()) + Environment.NewLine); } var request = new GenericReportRequest { CsvFilePath = csvFilePath, Model = csvStringBuilder.ToString() }; var isGenerated = GetResponse(request, RequestSubcriberChannelNames.CallCenterCallReportQueue, RequestSubcriberChannelNames.CallCenterCallReportChannel); if (!isGenerated) { return("CSV File Export failed!"); } DownloadZipFile(_tempMediaLocation, fileName); return("CSV File Export was succesful!"); }