private void GetContentHtml(RequestAssessmentPcsVo objAssessmentPcs, AssessmentDataVo assessmentDataVo) { if (objAssessmentPcs.Sections != null && objAssessmentPcs.Sections.Count > 0) { var header = objAssessmentPcs.Sections.FirstOrDefault(o => o.Order == 0); if (header != null) { for (int i = 1; i < 16; i++) { var field = "ContentHtml" + (i > 9 ? i.ToString() : "0" + i); var contentHtmlSection = GetPropValue(objAssessmentPcs.Sections[i], "ResultContent"); if (contentHtmlSection != null && !string.IsNullOrEmpty(contentHtmlSection.ToString())) { SetPropValue(assessmentDataVo, field, contentHtmlSection); } else { var contentSelected = GetPropValue(assessmentDataVo, field); if (contentSelected == null) { objAssessmentPcs.Sections[i].ResultContent = GetRootContentSection(objAssessmentPcs.Sections[i].Content, objAssessmentPcs, i); } else { objAssessmentPcs.Sections[i].ResultContent = assessmentDataVo.ContentHtml15; } } } assessmentDataVo.ContentHtml = CreateFileHtmlContent(TemplateHelpper.FormatTemplateWithContentTemplate(WebUtility.HtmlDecode(header.Content), new { section1 = string.IsNullOrEmpty(objAssessmentPcs.Sections[1].ResultContent) ? "" : objAssessmentPcs.Sections[1].ResultContent, section2 = string.IsNullOrEmpty(objAssessmentPcs.Sections[2].ResultContent) ? "" : objAssessmentPcs.Sections[2].ResultContent, section3 = string.IsNullOrEmpty(objAssessmentPcs.Sections[3].ResultContent) ? "" : objAssessmentPcs.Sections[3].ResultContent, section4 = string.IsNullOrEmpty(objAssessmentPcs.Sections[4].ResultContent) ? "" : objAssessmentPcs.Sections[4].ResultContent, section5 = string.IsNullOrEmpty(objAssessmentPcs.Sections[5].ResultContent) ? "" : objAssessmentPcs.Sections[5].ResultContent, section6 = string.IsNullOrEmpty(objAssessmentPcs.Sections[6].ResultContent) ? "" : objAssessmentPcs.Sections[6].ResultContent, section7 = string.IsNullOrEmpty(objAssessmentPcs.Sections[7].ResultContent) ? "" : objAssessmentPcs.Sections[7].ResultContent, section8 = string.IsNullOrEmpty(objAssessmentPcs.Sections[8].ResultContent) ? "" : objAssessmentPcs.Sections[8].ResultContent, section9 = string.IsNullOrEmpty(objAssessmentPcs.Sections[9].ResultContent) ? "" : objAssessmentPcs.Sections[9].ResultContent, section10 = string.IsNullOrEmpty(objAssessmentPcs.Sections[10].ResultContent) ? "" : objAssessmentPcs.Sections[10].ResultContent, section11 = string.IsNullOrEmpty(objAssessmentPcs.Sections[11].ResultContent) ? "" : objAssessmentPcs.Sections[11].ResultContent, section12 = string.IsNullOrEmpty(objAssessmentPcs.Sections[12].ResultContent) ? "" : objAssessmentPcs.Sections[12].ResultContent, section13 = string.IsNullOrEmpty(objAssessmentPcs.Sections[13].ResultContent) ? "" : objAssessmentPcs.Sections[13].ResultContent, section14 = string.IsNullOrEmpty(objAssessmentPcs.Sections[14].ResultContent) ? "" : objAssessmentPcs.Sections[14].ResultContent, section15 = string.IsNullOrEmpty(objAssessmentPcs.Sections[15].ResultContent) ? "" : objAssessmentPcs.Sections[15].ResultContent, })); } } }
private RequestAssessmentPcsVo GetUpdateAssessment(int id) { var result = new RequestAssessmentPcsVo(); //var SectionVos = new List<SectionVo>(); using (var context = new AssessmentContext()) { var assessment = context.Assessments.FirstOrDefault(o => o.Id == id); if (assessment != null) { //Case for the new assessment if (string.IsNullOrEmpty(assessment.AssessmentData) && string.IsNullOrEmpty(assessment.DisclosureFormData)) { return(GetNewAssessment(assessment.FileName, id)); } string encyptKey = ConfigurationManager.AppSettings["EncyptKey"]; if (string.IsNullOrEmpty(encyptKey)) { throw new Exception("EncyptKey not found in App.config"); } var dataJsonAssessmentData = new AssessmentDataVo(); if (!string.IsNullOrEmpty(assessment.AssessmentData)) { var decryptAssessmentData = EncryptHelper.Decrypt(assessment.AssessmentData, encyptKey); dataJsonAssessmentData = JsonConvert.DeserializeObject <AssessmentDataVo>(decryptAssessmentData); } var dataJsonDiscloseData = new DisclosureFormVo(); if (!string.IsNullOrEmpty(assessment.DisclosureFormData)) { var decryptDiscloseData = EncryptHelper.Decrypt(assessment.DisclosureFormData, encyptKey); dataJsonDiscloseData = JsonConvert.DeserializeObject <DisclosureFormVo>(decryptDiscloseData); } //always get content new result.Sections = GetHtmlToDisplay();//dataJsonAssessmentData.Sections; result.AssessmentSectionQuestions = dataJsonAssessmentData.AssessmentSectionQuestions; result.AssessmentPcsId = assessment.Id; result.AssessmentName = assessment.FileName; if (dataJsonDiscloseData != null && dataJsonDiscloseData.Providers != null && dataJsonDiscloseData.Providers.Count > 0) { foreach (var dt in dataJsonDiscloseData.Providers) { dt.Id = CaculatorHelper.TryParseIntFromStr(dt.Mpi); } } result.DisclosureFormVo = dataJsonDiscloseData; //parse string to DateTime if (result.DisclosureFormVo != null) { if (result.DisclosureFormVo.Member != null) { result.DisclosureFormVo.Member.DobStr = result.DisclosureFormVo.Member.Dob != null? result.DisclosureFormVo.Member.Dob.GetValueOrDefault().ToShortDateString() : ""; } result.DisclosureFormVo.DateSignedStr = result.DisclosureFormVo.DateSigned != null? result.DisclosureFormVo.DateSigned.GetValueOrDefault().ToShortDateString() : ""; result.DisclosureFormVo.TheFollowingDateStr = result.DisclosureFormVo.TheFollowingDate != null ? result.DisclosureFormVo.TheFollowingDate.GetValueOrDefault().ToShortDateString() : ""; } return(result); } return(GetNewAssessment()); } return(result); }
public List <MessageErrorVo> CheckInValidBeforeExport(DisclosureFormVo disclosureFormVm, AssessmentDataVo assessmentForm) { var listError = new List <MessageErrorVo>(); ////check error disclosure form //var listErrorDisclosureForm = CheckInValidDisclosureForm(disclosureFormVm); //if (listErrorDisclosureForm.Count > 0) //{ // listError.AddRange(listErrorDisclosureForm); //} //check match MID var fieldMid = assessmentForm.AssessmentSectionQuestions.FirstOrDefault(o => o.Order == 13); if (fieldMid != null) { if (string.IsNullOrEmpty(fieldMid.Field01)) { listError.Add(new MessageErrorVo { MessageError = "MID at PCST Form is required." }); } else if (!string.IsNullOrEmpty(disclosureFormVm.Member.Mid) && !string.IsNullOrEmpty(fieldMid.Field01)) { if (disclosureFormVm.Member.Mid != fieldMid.Field01) { listError.Add(new MessageErrorVo { MessageError = "MID at Disclosure Form not match PCST Form." }); } } } //check is Expedited Request var fieldRequestType = assessmentForm.AssessmentSectionQuestions.FirstOrDefault(o => o.Order == 5); var fieldPeriod = assessmentForm.AssessmentSectionQuestions.FirstOrDefault(o => o.Order == 64); if (fieldRequestType != null && fieldRequestType.Field01 != null) { if (fieldRequestType.Field01.ToString() == "2") { if (fieldPeriod != null && fieldPeriod.Field01 != null) { if (fieldPeriod.Field01.ToString() != "5") { listError.Add(new MessageErrorVo { MessageError = "PCST Form - Item 64: You must be chosen 1 months (4 weeks) because this request is Expedited Request." }); } } } } return(listError); }
public dynamic Save(string parameters) { string encyptKey = ConfigurationManager.AppSettings["EncyptKey"]; if (string.IsNullOrEmpty(encyptKey)) { throw new Exception("EncyptKey not found in App.config"); } var dataJson = EncryptHelper.Base64Decode(parameters); var jSettings = new JsonSerializerSettings { Formatting = Formatting.Indented, DateTimeZoneHandling = DateTimeZoneHandling.Utc }; jSettings.Converters.Add(new DefaultWrongFormatDeserialize()); var viewModel = JsonConvert.DeserializeObject <RequestAssessmentPcsVo>(dataJson, jSettings); TrackingCompleteInformation(viewModel); var listDisclodureError = new List <MessageErrorVo>(); var IsDisclosureFormComplete = true; var listError = new List <MessageErrorVo>(); if (viewModel.IsSaveAll == true) { var checkDisclosureForm = CheckInValidDisclosureForm(viewModel.DisclosureFormVo); if (checkDisclosureForm.Count > 0) { if (viewModel.MessageErrorTotal == null) { viewModel.MessageErrorTotal = new List <MessageErrorVo>(); viewModel.MessageErrorTotal.AddRange(checkDisclosureForm); } else { viewModel.MessageErrorTotal.AddRange(checkDisclosureForm); } listDisclodureError = checkDisclosureForm; IsDisclosureFormComplete = false; } var checkMid = CheckMidDisclosureFormAndPcstForm(viewModel); if (checkMid.Count > 0) { if (viewModel.MessageErrorTotal == null) { viewModel.MessageErrorTotal = new List <MessageErrorVo>(); viewModel.MessageErrorTotal.AddRange(checkMid); } else { viewModel.MessageErrorTotal.AddRange(checkMid); } } if (viewModel.MessageErrorTotal != null && viewModel.MessageErrorTotal.Count > 0) { var index = 0; foreach (var item in viewModel.MessageErrorTotal) { index++; item.Index = index; } //var result = new ObjectReturnVo(); //result.Error = viewModel.MessageErrorTotal; //result.Id = viewModel.AssessmentPcsId; //return result; listError = viewModel.MessageErrorTotal; } } var assessmentData = new AssessmentDataVo { Sections = viewModel.Sections, AssessmentSectionQuestions = viewModel.AssessmentSectionQuestions, }; //GetContentHtml(viewModel, assessmentData); var encryptAssessmentData = EncryptHelper.Encrypt(JsonConvert.SerializeObject(assessmentData), encyptKey); //parse string to DateTime if (viewModel.DisclosureFormVo.Member != null) { viewModel.DisclosureFormVo.Member.Dob = CaculatorHelper.TryParseDatTimeFromStr(viewModel.DisclosureFormVo.Member.DobStr);//.GetValueOrDefault(); if (viewModel.DisclosureFormVo.Member.Signature == "_blank") { viewModel.DisclosureFormVo.Member.Signature = null; } } viewModel.DisclosureFormVo.DateSigned = CaculatorHelper.TryParseDatTimeFromStr(viewModel.DisclosureFormVo.DateSignedStr); //.GetValueOrDefault(); viewModel.DisclosureFormVo.TheFollowingDate = CaculatorHelper.TryParseDatTimeFromStr(viewModel.DisclosureFormVo.TheFollowingDateStr); //.GetValueOrDefault(); if (viewModel.DisclosureFormVo.Guardian != null && viewModel.DisclosureFormVo.Guardian.Signature == "_blank") { viewModel.DisclosureFormVo.Guardian.Signature = null; } if (viewModel.DisclosureFormVo.IsHasProviderAgency) { //set MPI == id if (viewModel.DisclosureFormVo.Providers != null && viewModel.DisclosureFormVo.Providers.Count > 0) { foreach (var dt in viewModel.DisclosureFormVo.Providers) { if (dt.Id != null && dt.Id.GetValueOrDefault() > 0) { dt.Mpi = dt.Id.ToString(); } } } } else { viewModel.DisclosureFormVo.Providers = new List <ProviderDisclosureFormViewModel>(); } var encryptDisclosureFormData = EncryptHelper.Encrypt(JsonConvert.SerializeObject(viewModel.DisclosureFormVo), encyptKey); var encryptMid = EncryptHelper.Encrypt(JsonConvert.SerializeObject(GetMid(viewModel)), encyptKey); var extensionVm = new ExtensionAssessment { DisclosureFormIsComplete = IsDisclosureFormComplete, ErrorDisclosureForm = listDisclodureError }; var extensionStr = JsonConvert.SerializeObject(extensionVm); using (var context = new AssessmentContext()) { //Update if (viewModel.AssessmentPcsId > 0) { var assessment = context.Assessments.FirstOrDefault(o => o.Id == viewModel.AssessmentPcsId); if (assessment != null) { assessment.FileName = viewModel.AssessmentName; assessment.ModifiedOn = DateTime.Now; assessment.AssessmentData = encryptAssessmentData; assessment.DisclosureFormData = encryptDisclosureFormData; assessment.Mid = encryptMid; assessment.Extension = extensionStr; context.Entry(assessment).State = EntityState.Modified; context.SaveChanges(); var result = new ObjectReturnVo(); result.Id = assessment.Id; result.Error = listError.Count > 0 ? listError : null; return(result); } else { var result = new ObjectReturnVo(); result.Error = new List <MessageErrorVo> { new MessageErrorVo { MessageError = "This record was delete." } }; result.Id = 0; return(result); } } //Add else { var entity = new Assessment { FileName = viewModel.AssessmentName, FilePath = "", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, AssessmentData = encryptAssessmentData, DisclosureFormData = encryptDisclosureFormData, Mid = encryptMid, Extension = extensionStr }; context.Entry(entity).State = EntityState.Added; context.SaveChanges(); var result = new ObjectReturnVo(); result.Id = entity.Id; result.Error = listError; return(result); } } }
private void ExportAssessment(int assessmentId) { string encyptKey = ConfigurationManager.AppSettings["EncyptKey"]; if (string.IsNullOrEmpty(encyptKey)) { throw new Exception("EncyptKey not found in App.config"); } var assessment = _assessmentService.GetById(assessmentId); if (assessment != null) { var isShowExportForm = true; var listError = new List <MessageErrorVo>(); var dataJsonDiscloseData = new DisclosureFormVo(); var dataJsonAssessment = new AssessmentDataVo(); if (string.IsNullOrEmpty(assessment.DisclosureFormData)) { isShowExportForm = false; var errorMsg = "To export assessment, please input data fully to Disclosure Form.\n"; MessageBox.Show(errorMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (!string.IsNullOrEmpty(assessment.DisclosureFormData)) { var decryptDiscloseData = EncryptHelper.Decrypt(assessment.DisclosureFormData, encyptKey); dataJsonDiscloseData = JsonConvert.DeserializeObject <DisclosureFormVo>(decryptDiscloseData); if (!string.IsNullOrEmpty(assessment.AssessmentData)) { var decryptAssessment = EncryptHelper.Decrypt(assessment.AssessmentData, encyptKey); dataJsonAssessment = JsonConvert.DeserializeObject <AssessmentDataVo>(decryptAssessment); } var listErrorDisclosureForm = _assessmentService.CheckInValidDisclosureForm(dataJsonDiscloseData); listError = _assessmentService.CheckInValidBeforeExport(dataJsonDiscloseData, dataJsonAssessment); if (listErrorDisclosureForm != null && listErrorDisclosureForm.Count > 0) { if (listError != null && listError.Count > 0) { listErrorDisclosureForm.AddRange(listError); } isShowExportForm = false; var errorMsg = "To export assessment, please input data fully to Disclosure Form.\n" + "Following business rules are failed:\n"; foreach (var item in listErrorDisclosureForm) { errorMsg += " - " + item.MessageError.Replace("(Disclosure Form)", "") + "\n"; } MessageBox.Show(errorMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (listError != null && listError.Count > 0) { isShowExportForm = false; var errorMsg = "Following business rules are failed:\n"; foreach (var item in listError) { errorMsg += " - " + item.MessageError.Replace("(Disclosure Form)", "") + "\n"; } MessageBox.Show(errorMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (isShowExportForm) { var form = new FrmExport(assessment); form.ShowDialog(); } } }