protected override bool RealValidate(IResponseElementProvider elementToValidate, QuestionnaireDto questionnaire) { bool hasElement = false; bool hasEmptyElements = false; List<ResponseDto> responses = elementToValidate.GetResponseDto(-1); List<int> validationHints = null; if (responses != null && responses.Count > 0) { foreach (ResponseDto response in responses) { QuestionResponseDto questionResponse = response as QuestionResponseDto; if (questionResponse != null) { hasElement = true; if (String.IsNullOrEmpty(questionResponse.ChoiceText)) { hasEmptyElements = true; break; } else { if (questionResponse.ChoiceText.Length > 4000) { validationHints = new List<int>(); validationHints.Add(PageElementWithErrorDto.InvalidInputTooLong); } } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissmatch, "Choices validator does not accept a response of type \"" + response.GetType().Name + "\""); } } } bool retval = false; if (validationHints == null) { if (elementToValidate.PageElement.IsRequired) { if (!hasEmptyElements && hasElement) { retval = true; } } else { retval = true; } } else { elementToValidate.SetValidationHints(validationHints); } elementToValidate.IsValid = retval; return retval; }
protected override bool RealValidate(IResponseElementProvider elementToValidate, QuestionnaireDto questionnaire) { bool hasElements = false; bool hasMissingTexts = false; List<ResponseDto> responses = elementToValidate.GetResponseDto(-1); if (responses != null && responses.Count > 0) { hasElements = true; foreach (ResponseDto response in responses) { QuestionResponseDto questionResponse = response as QuestionResponseDto; if (questionResponse != null) { PageElementChoiceDto choice = elementToValidate.Choices.Find(delegate(PageElementChoiceDto cur) { return cur.ChoiceId == questionResponse.ChoiceId; }); if (choice != null) { if (choice.HasExtraTextField && String.IsNullOrEmpty(questionResponse.ChoiceText)) { hasMissingTexts = true; } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissmatch, "Choices validator found response (" + questionResponse.ChoiceId + ") which does not have a corresponding choice"); } } else { throw new BugException("Choices validator does not accept a response of type \"" + response.GetType().Name + "\""); } } } bool retval = false; if (!hasMissingTexts) { if (elementToValidate.PageElement.IsRequired) { if (hasElements) { retval = true; } } else { retval = true; } } elementToValidate.IsValid = retval; return retval; }
protected override bool RealValidate(IResponseElementProvider elementToValidate, QuestionnaireDto questionnaire) { List<ResponseDto> responses = elementToValidate.GetResponseDto(-1); List<int> validationHints = null; PersonalDataSectionDto elementDto = elementToValidate.PageElement as PersonalDataSectionDto; if (elementDto != null) { validationHints = new List<int>(); validationHints1 = new List<int>(); if (responses != null && responses.Count == 1) { PersonalResponseDto response = responses[0] as PersonalResponseDto; if (response != null) { MakeFunnyThingsHappen(elementDto, response, validationHints); } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissing, "Personal validator did not receive a single personal response"); } } else { MakeFunnyThingsHappen(elementDto, null, validationHints); } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissing, "Personal validator did not receive a page element"); } bool retval = true; if (validationHints.Count > 0 || validationHints1.Count > 0) { retval = false; if (validationHints.Count > 0) elementToValidate.SetValidationHints(validationHints); if (validationHints1.Count > 0) elementToValidate.SetValidationNumberHints(validationHints1); } elementToValidate.IsValid = retval; return retval; }
protected override bool RealValidate(IResponseElementProvider elementToValidate, QuestionnaireDto questionnaire) { bool invalidPhone = true; bool invalidCallback = true; bool hasPhone = false; List<ResponseDto> responses = elementToValidate.GetResponseDto(-1); if (responses != null && responses.Count > 0) { PageElementChoiceDto callBack = null; PageElementChoiceDto phone = null; foreach (PageElementChoiceDto dto in elementToValidate.Choices) { if (dto.LovKey == "resp_phone") { phone = dto; } else if (dto.LovKey == "callback_time") { callBack = dto; } } if (phone != null) { QuestionResponseDto phoneResponse = responses.Find(delegate(ResponseDto cur) { QuestionResponseDto me = cur as QuestionResponseDto; return me != null && me.ChoiceId == phone.ChoiceId; }) as QuestionResponseDto; if (phoneResponse != null) { hasPhone = true; invalidPhone = !DataValidation.ValidatePhoneNumberCRM(phoneResponse.ChoiceText, true); } } if (callBack != null) { QuestionResponseDto callResponse = responses.Find(delegate(ResponseDto cur) { QuestionResponseDto me = cur as QuestionResponseDto; return me != null && me.ChoiceId == callBack.ChoiceId; }) as QuestionResponseDto; if (callResponse != null) { invalidCallback = !callResponse.ListOfValuesId.HasValue; } } if (!invalidCallback && !invalidPhone) { SpecificCrmResponseDto crm = responses.Find(delegate(ResponseDto cur) { return cur is SpecificCrmResponseDto; }) as SpecificCrmResponseDto; if (crm != null) { if (crm.ElementType == SpecificCrmResponseDto.ElementTypeRequestCallback && crm.QuestionId == elementToValidate.PageElement.ElementId && crm.PageId == elementToValidate.PageElement.PageId && crm.CrmSubmit == questionnaire.SendToCrm && crm.CidSubmit == false && crm.QuestionnaireId == questionnaire.QuestionnaireId && !String.IsNullOrEmpty(crm.RespDesc)) { } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrect, "crm callback requires a valid specific crm response"); } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissing, "crm callback requires a specific crm response"); } } } bool retval = true;//!invalidCallback && !invalidPhone; if (elementToValidate.PageElement.IsRequired || hasPhone) { List<int> validationHints = new List<int>(); if (invalidPhone) { validationHints.Add(PageElementReqDto.InvalidTelephoneNumber); retval = false; } if (invalidCallback) { validationHints.Add(PageElementReqDto.InvalidCallBackTime); retval = false; } if (!retval) { elementToValidate.SetValidationHints(validationHints); } } elementToValidate.IsValid = retval; return retval; }
protected override bool RealValidate(IResponseElementProvider elementToValidate, QuestionnaireDto questionnaire) { bool hasElements = false; int firstElement = 0; bool hasMissingTexts = false; List<ResponseDto> responses = elementToValidate.GetResponseDto(-1); if (responses != null && responses.Count > 0) { List<PageElementChoiceDto> choices = elementToValidate.Choices; if (choices == null || choices.Count < 1) { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissing, "Drop down validator requires choices to validate"); } firstElement = choices[0].ChoiceId; if (responses != null && responses.Count > 0) { foreach (ResponseDto response in responses) { QuestionResponseDto questionResponse = response as QuestionResponseDto; if (questionResponse != null) { hasElements = true; if (questionResponse.ChoiceId == firstElement) { hasMissingTexts = true; } if (isExtraText(elementToValidate.PageElement.ElementId, questionResponse.ChoiceId)) { if(questionResponse.ChoiceText != null) { if (String.IsNullOrEmpty(questionResponse.ChoiceText)) hasMissingTexts = true; } } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissmatch, "Choices validator does not accept a response of type \"" + response.GetType().Name + "\""); } } } } bool retval = false; if (elementToValidate.PageElement.IsRequired) { if (hasElements) { if (!hasMissingTexts) { retval = true; } } } else { if (!(hasMissingTexts)) { retval = true; } else { retval = false; } } elementToValidate.IsValid = retval; return retval; }
protected override bool RealValidate(IResponseElementProvider elementToValidate, QuestionnaireDto questionnaire) { List<ResponseDto> responses = elementToValidate.GetResponseDto(-1); List<int> validationHints = new List<int>(); if (responses != null && responses.Count == 2) { PrivacyResponseDto response = responses[0] as PrivacyResponseDto; if (response != null) { PrivacyDataSectionDto elementDto = elementToValidate.PageElement as PrivacyDataSectionDto; if (elementDto != null) { if (!String.IsNullOrEmpty(elementDto.Email)) { if (!response.ContactByEmail.HasValue) { validationHints.Add(PrivacyDataSectionDto.InvalidEmail); } else { if (response.ContactByEmail.Value) { if (!String.IsNullOrEmpty(elementDto.EmailPreferences)) { if (!response.EmailPreferences.HasValue) { validationHints.Add(PrivacyDataSectionDto.InvalidEmailPreferences); } } } } } if (!String.IsNullOrEmpty(elementDto.Phone)) { if (!response.ContactByPhone.HasValue) { validationHints.Add(PrivacyDataSectionDto.InvalidPhone); } } if (!String.IsNullOrEmpty(elementDto.Post)) { if (!response.ContactByPost.HasValue) { validationHints.Add(PrivacyDataSectionDto.InvalidPost); } } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissing, "Privacy validator did not receive a page element"); } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissing, "Privacy validator did not receive a single privacy response"); } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissing, "Privacy validator did not receive a single privacy response"); } bool retval = true; if (validationHints.Count > 0) { retval = false; elementToValidate.SetValidationHints(validationHints); } elementToValidate.IsValid = retval; return retval; }
protected override bool RealValidate(IResponseElementProvider elementToValidate, QuestionnaireDto questionnaire) { bool invalidFax = true; bool invalidEmail = true; bool hasFax = false; bool hasEmail = false; List<ResponseDto> responses = elementToValidate.GetResponseDto(-1); if (responses != null && responses.Count > 0) { PageElementChoiceDto fax = null; PageElementChoiceDto email = null; foreach (PageElementChoiceDto dto in elementToValidate.Choices) { if (dto.LovKey == "resp_email") { email = dto; } else if (dto.LovKey == "resp_fax") { fax = dto; } } if (fax != null) { QuestionResponseDto phoneResponse = responses.Find(delegate(ResponseDto cur) { QuestionResponseDto me = cur as QuestionResponseDto; return me != null && me.ChoiceId == fax.ChoiceId; }) as QuestionResponseDto; if (phoneResponse != null) { hasFax = true; invalidFax = !DataValidation.ValidatePhoneNumberCRM(phoneResponse.ChoiceText, true); //if (!phoneResponse.ListOfValuesId.HasValue) //{ // throw new BugException("fax request requires a correct entry for shipping method"); //} } } if (email != null) { QuestionResponseDto callResponse = responses.Find(delegate(ResponseDto cur) { QuestionResponseDto me = cur as QuestionResponseDto; return me != null && me.ChoiceId == email.ChoiceId; }) as QuestionResponseDto; if (callResponse != null) { hasEmail = true; invalidEmail = !DataValidation.ValidateEmail(callResponse.ChoiceText, true); //if (!callResponse.ListOfValuesId.HasValue) //{ // throw new BugException("phone request requires a correct entry for shipping method"); //} } } if (!invalidEmail || !invalidFax) { SpecificCrmResponseDto crm = responses.Find(delegate(ResponseDto cur) { return cur is SpecificCrmResponseDto; }) as SpecificCrmResponseDto; if (crm != null) { if (crm.ElementType == SpecificCrmResponseDto.ElementTypeRequestMoreInfo && crm.QuestionId == elementToValidate.PageElement.ElementId && crm.PageId == elementToValidate.PageElement.PageId && crm.CrmSubmit == questionnaire.SendToCrm && crm.CidSubmit == false && crm.QuestionnaireId == questionnaire.QuestionnaireId && !String.IsNullOrEmpty(crm.RespDesc)) { } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrect, "crm more info requires a valid specific crm response"); } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissing, "crm more info requires a specific crm response"); } } } bool retval = false;// (hasEmail && !invalidEmail) || (hasFax && !invalidFax); List<int> validationHints = new List<int>(); if (hasEmail) { if (invalidEmail) { validationHints.Add(PageElementReqDto.InvalidEmail); } else { retval = true; } } else { if (hasFax) { if (invalidFax) { validationHints.Add(PageElementReqDto.InvalidFaxNumber); } else { retval = true; } } else { retval = !elementToValidate.PageElement.IsRequired; } } elementToValidate.SetValidationHints(validationHints); elementToValidate.IsValid = retval; return retval; }