public ActionResult U65GetReportData([DataSourceRequest] DataSourceRequest request) { List <U65Certificate> U65ModelList = null; U65ModelList = BCBSDataAccess.GetDataForU65Report(); if (U65ModelList == null) { return(Json(new List <U65Certificate>(), JsonRequestBehavior.AllowGet)); } return(Json(U65ModelList.ToDataSourceResult(request), JsonRequestBehavior.AllowGet)); }
public ActionResult U65ExportData() { MemoryStream memoryStream = null; List <U65Certificate> U65CourseModelList = null; const string header = "Agent Name, Agency Name,Address,Managing Health Agent Name,Agent Email,Work Phone Number,National Producer Number,FFM ID,Assessment Score,Pass/Fail Status,Date of Completion"; const string format = "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}";//,{8},{9},{10}"; string content = string.Empty; U65CourseModelList = BCBSDataAccess.GetDataForU65Report(); memoryStream = new MemoryStream(); if (U65CourseModelList != null && U65CourseModelList.Count > 0) { TextWriter tw = new StreamWriter(memoryStream); tw.WriteLine(header); foreach (var item in U65CourseModelList) { item.AgentName = !String.IsNullOrEmpty(item.AgentName) ? (item.AgentName.Contains(",") ? item.AgentName.Replace(',', '|') : item.AgentName): string.Empty; item.AgencyName = !String.IsNullOrEmpty(item.AgencyName)? (item.AgencyName.Contains(",") ? item.AgencyName.Replace(',', '|') : item.AgencyName) : string.Empty; item.AgencyAddress = !String.IsNullOrEmpty(item.AgencyAddress)? (item.AgencyAddress.Contains(",") ? item.AgencyAddress.Replace(',', '|') : item.AgencyAddress) : string.Empty; item.AgentManagingHealth = !String.IsNullOrEmpty(item.AgentManagingHealth)? (item.AgentManagingHealth.Contains(",") ? item.AgentManagingHealth.Replace(',', '|') : item.AgentManagingHealth) : string.Empty; item.AgentEmail = !String.IsNullOrEmpty(item.AgentEmail)? (item.AgentEmail.Contains(",") ? item.AgentEmail.Replace(',', '|') : item.AgentEmail) : string.Empty; item.WorkPhoneNumber = !String.IsNullOrEmpty(item.WorkPhoneNumber)? (item.WorkPhoneNumber.Contains(",") ? item.WorkPhoneNumber.Replace(',', '|') : item.WorkPhoneNumber) : string.Empty; item.NationalProducerNumber = !String.IsNullOrEmpty(item.NationalProducerNumber)? (item.NationalProducerNumber.Contains(",") ? item.NationalProducerNumber.Replace(',', '|') : item.NationalProducerNumber) : string.Empty; item.FFMID = !String.IsNullOrEmpty(item.FFMID) ? (item.FFMID.Contains(",") ? item.FFMID.Replace(',', '|') : item.FFMID) : string.Empty; item.AssessmentScore = item.AssessmentScore; //item.PassFailStatus = item.PassFailStatus; item.PassFailStatusstring = Convert.ToBoolean(item.PassFailStatus) ? "PASS" : "FAIL"; item.DateofCompletion = item.DateofCompletion; content = string.Format(format, item.AgentName, item.AgencyName, item.AgencyAddress, item.AgentManagingHealth, item.AgentEmail, item.WorkPhoneNumber, item.NationalProducerNumber, item.FFMID, item.AssessmentScore, item.PassFailStatusstring, item.DateofCompletion.ToString("MM-dd-yyyy h:mm:ss tt")); tw.WriteLine(content); } tw.Flush(); } string contentType = "application/octet-stream"; byte[] pdfdata = null; pdfdata = memoryStream.ToArray(); var filaName = ConfigurationManager.AppSettings["CSVFileName"]; return(File(pdfdata, contentType, filaName)); }