public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (FirstName.Trim().Length == 0) { yield return(new ValidationResult("FirstName cannot be empty or blank ", new[] { "FirstName" })); } if (LastName.Trim().Length == 0) { yield return(new ValidationResult("FirstName cannot be empty or blank ", new[] { "LastName" })); } if (UseCanadaPost == true) { if (string.IsNullOrEmpty(Street)) { yield return(new ValidationResult("Street is Required ", new[] { "Street" })); } if (string.IsNullOrEmpty(City)) { yield return(new ValidationResult("City is Required ", new[] { "City" })); } Street = Street.Trim(); City = City.Trim(); } if (UseCanadaPost == false) { if (string.IsNullOrEmpty(Email)) { yield return(new ValidationResult("Email is Required ", new[] { "Email" })); } else { Email = Email.Trim(); } } // MemberId = _context.Member.Max(a => a.MemberId) + 1; //var memberid = _context.Member.Where(a => a.MemberId == MemberId).FirstOrDefault(); //if (memberid != null) //{ // yield return new ValidationResult("Member is already on file", new[] { "MemberId" }); //} ProvinceCode = ProvinceCode.Trim(); ProvinceCode = ProvinceCode.ToUpper(); if (ProvinceCode.Length != 2) { yield return(new ValidationResult("ProvinceCode length is not match ", new[] { "ProvinceCode" })); } var province = _context.Member.Where(a => a.ProvinceCode == ProvinceCode).FirstOrDefault(); if (province == null) { yield return(new ValidationResult("ProvinceCode is not match ", new[] { "ProvinceCode" })); } if (!string.IsNullOrEmpty(PostalCode)) { PostalCode = PostalCode.ToUpper().Trim(); Regex PostalValidation = new Regex(@"^(?!.*[DFIOQU])[A-VXY][0-9][A-Z][0-9][A-Z][0-9]$"); if (!PostalValidation.IsMatch(PostalCode)) { yield return(new ValidationResult("PostalCode is not match ", new[] { "PostalCode" })); } else { PostalCode = PostalCode.Insert(3, " "); } } if (!string.IsNullOrEmpty(HomePhone)) { HomePhone = HomePhone.Trim(); Regex PhoneValidation = new Regex(@"^\(?[0-9]{3}(\-|\)) ?[0-9]{3}-[0-9]{4}$"); if (HomePhone.Length != 10 && !PhoneValidation.IsMatch(HomePhone)) { yield return(new ValidationResult("Home Phone should only be 10 digits", new[] { "HomePhone" })); } else { HomePhone = HomePhone.Insert(3, "-"); HomePhone = HomePhone.Insert(7, "-"); } } if (!string.IsNullOrEmpty(SpouseFirstName)) { if (!string.IsNullOrEmpty(SpouseLastName)) { SpouseFirstName = SpouseFirstName.Trim(); SpouseLastName = SpouseLastName.Trim(); FullName = LastName + ", " + FirstName + "&" + SpouseLastName + ", " + SpouseFirstName; } else { FullName = LastName + ", " + FirstName + "&" + SpouseFirstName; } } else { FirstName = FirstName.Trim(); LastName = LastName.Trim(); FullName = LastName + ", " + FirstName; } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { // first name FirstName = FirstName.Trim(); FirstName = HMBPClassLibrary.HMBPValidations.HMBPCapitalize(FirstName); // last name LastName = LastName.Trim(); LastName = HMBPClassLibrary.HMBPValidations.HMBPCapitalize(LastName); // spouse first name SpouseFirstName = SpouseFirstName.Trim(); SpouseFirstName = HMBPClassLibrary.HMBPValidations.HMBPCapitalize(SpouseFirstName); // spouse last name SpouseLastName = SpouseLastName.Trim(); SpouseLastName = HMBPClassLibrary.HMBPValidations.HMBPCapitalize(SpouseLastName); if (String.IsNullOrEmpty(SpouseFirstName)) { SpouseFirstName = null; } else { SpouseFirstName = HMBPClassLibrary.HMBPValidations.HMBPCapitalize(SpouseFirstName.Trim()); } if (String.IsNullOrEmpty(SpouseLastName)) { SpouseLastName = null; } else { SpouseLastName = HMBPClassLibrary.HMBPValidations.HMBPCapitalize(SpouseLastName.Trim()); } // street Street = Street.Trim(); Street = HMBPClassLibrary.HMBPValidations.HMBPCapitalize(Street); if (String.IsNullOrEmpty(Street)) { Street = null; } else { Street = HMBPClassLibrary.HMBPValidations.HMBPCapitalize(Street.Trim()); } // city City = City.Trim(); City = HMBPClassLibrary.HMBPValidations.HMBPCapitalize(City); if (String.IsNullOrEmpty(City)) { City = null; } else { City = HMBPClassLibrary.HMBPValidations.HMBPCapitalize(City.Trim()); } // postal code if (PostalCode == null || PostalCode == "") { PostalCode = ""; } else { PostalCode = PostalCode.Trim(); if (HMBPClassLibrary.HMBPValidations.HMBPPostalCodeValidation(PostalCode)) { PostalCode = HMBPClassLibrary.HMBPValidations.HMBPPostalCodeFormat(PostalCode); } else { string _postalCode = ""; _postalCode = PostalCode; if (HMBPClassLibrary.HMBPValidations.HMBPZipCodeValidation(ref _postalCode)) { PostalCode = _postalCode; } else { yield return(new ValidationResult("error", new[] { "PostalCode" })); } } if (ProvinceCode == null) { yield return(new ValidationResult("error", new[] { "ProvinceCode" })); } } // email if (string.IsNullOrEmpty(Email)) { Email = null; } else // trim { Email = Email.Trim(); } // comment if (string.IsNullOrEmpty(Comment)) { Comment = null; } else // trim { Comment = Comment.Trim(); } //home phone reformat HomePhone = HMBPClassLibrary.HMBPValidations.HMBPExtractDigits(HomePhone.Trim()); if (HomePhone.Length != 10) { yield return(new ValidationResult("The home phone can only contain 10 digits", new[] { nameof(HomePhone) })); } else { HomePhone = HomePhone.Insert(3, "-").Insert(7, "-"); } //validate Joined year if (YearJoined.HasValue) { if (YearJoined > DateTime.Now.Year) { YearJoined = null; yield return(new ValidationResult("The year cant be in the future", new[] { nameof(YearJoined) })); } } //Full name if (String.IsNullOrEmpty(SpouseFirstName) && String.IsNullOrEmpty(SpouseLastName)) { FullName = LastName + ", " + FirstName; } else if (!String.IsNullOrEmpty(SpouseFirstName)) { if (String.IsNullOrEmpty(SpouseLastName) || SpouseLastName == LastName) { FullName = LastName + ", " + FirstName + " & " + SpouseFirstName; } else if (!String.IsNullOrEmpty(SpouseLastName)) { FullName = LastName + ", " + FirstName + " & " + SpouseLastName + ", " + SpouseFirstName; } } yield return(ValidationResult.Success); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { PatientsContext _context = new PatientsContext(); if (string.IsNullOrEmpty(FirstName) || FirstName == " ") { yield return(new ValidationResult("First name is a required field and cannot be blank spaces", new[] { "FirstName" })); } else { FirstName = FirstName.Trim(); FirstName = MBValidations.MBCapitalize(FirstName); } if (string.IsNullOrEmpty(LastName) || LastName == " ") { yield return(new ValidationResult("Last name is a required field and should not be blank space", new[] { "LastName" })); } else { LastName = LastName.Trim(); LastName = MBValidations.MBCapitalize(LastName); } if (string.IsNullOrEmpty(Gender) || Gender == " ") { yield return(new ValidationResult("Gender is a required field and should not start with a blank space", new[] { "Gender" })); } else { Gender = Gender.Trim(); Gender = MBValidations.MBCapitalize(Gender); } if (!string.IsNullOrEmpty(Address)) { Address = Address.Trim(); Address = MBValidations.MBCapitalize(Address); } if (!string.IsNullOrEmpty(City)) { City = City.Trim(); City = MBValidations.MBCapitalize(City); } if (!string.IsNullOrEmpty(ProvinceCode)) { ProvinceCode = ProvinceCode.Trim(); Province Pro = new Province(); string error = ""; ProvinceCode = ProvinceCode.ToUpper(); try { Pro = _context.Province.Where(m => m.ProvinceCode == ProvinceCode).FirstOrDefault(); //var country = Pro.CountryCode; } catch (Exception e) { error = e.GetBaseException().Message; } if (Pro == null) { yield return(new ValidationResult(error, new[] { nameof(ProvinceCode) })); } else { if (PostalCode != null) { PostalCode = PostalCode.Trim(); bool val = false; string USZipCode = PostalCode; if (Pro.CountryCode == "CA") { var x = Pro.FirstPostalLetter; char[] charArr = x.ToCharArray(); foreach (char ch in charArr) { if (Convert.ToChar(PostalCode.Substring(0, 1).ToUpper()) == ch) { //if(PostalCode.StartsWith(ch)) val = true; } } if (!val) { yield return(new ValidationResult("Postal code entered is not a valid code for the selected province", new[] { "PostalCode" })); } if (!MBValidations.MBPostalCodeValidation(PostalCode)) { yield return(new ValidationResult("Postal code entered is not in valid format", new[] { "PostalCode" })); } else { PostalCode = MBValidations.MBPostalCodeFormat(PostalCode); } } if (Pro.CountryCode == "US") { if (!MBValidations.MBZipCodeValidation(ref USZipCode)) { yield return(new ValidationResult("Zip code entered is not in valid format", new[] { "PostalCode" })); } else { PostalCode = USZipCode; } } } } } if (Ohip != null) { Ohip = Ohip.ToUpper(); Regex pattern = new Regex(@"^\d\d\d\d-\d\d\d-\d\d\d-[a-z][a-z]$", RegexOptions.IgnoreCase); if (!pattern.IsMatch(Ohip)) { yield return(new ValidationResult("The value for OHIP entered is not in valid format", new[] { "Ohip" })); } } if (HomePhone != null) { HomePhone = HomePhone.Trim(); if (HomePhone.Length != 10) { yield return(new ValidationResult("The Home Phone Number entered should be exactly 10 digits", new[] { "HomePhone" })); } HomePhone = HomePhone.Insert(3, "-"); HomePhone = HomePhone.Insert(7, "-"); } if (DateOfBirth != null) { if (DateOfBirth > DateTime.Now) { yield return(new ValidationResult("The date of Birth cannot be greater than current date", new[] { "DateOfBirth" })); } } if (Deceased) { if (DateOfDeath == null) { yield return(new ValidationResult("The date of death is required if the deceased checkbox is chec", new[] { "DateOfDeath" })); } } else { DateOfDeath = null; } if (DateOfDeath != null) { if (DateOfDeath > DateTime.Now || DateOfDeath < DateOfBirth) { yield return(new ValidationResult("The date of death cannot be greater than current date and before the Date of birth", new[] { "DateOfBirth" })); } } if (Gender != "M" && Gender != "F" && Gender != "X") { yield return(new ValidationResult("The value for gender entered must be M, F or X", new[] { "Gender" })); } yield return(ValidationResult.Success); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (ProvinceCode != null) { if (ProvinceCode.Length != 2) { yield return(new ValidationResult("Province code cannot be longer than 2 characters", new[] { "ProvinceCode" })); } else { var provinceContext = _context.Province.Where(a => a.ProvinceCode == ProvinceCode).FirstOrDefault(); if (provinceContext == null) { yield return(new ValidationResult("Invalid province code", new[] { "ProvinceCode" })); } else { ProvinceCode = ProvinceCode.Trim().ToUpper(); } } } Regex postalCodeRegex = new Regex((@"^[A-Za-z]{1}[0-9]{1}[A-Za-z]{1}\s{0,1}[0-9]{1}[A-Za-z]{1}[0-9]{1}"), RegexOptions.IgnoreCase); if (PostalCode != null) { if (postalCodeRegex.IsMatch(PostalCode.Trim())) { if (!PostalCode.Contains(" ")) { PostalCode = PostalCode.Insert(3, " "); PostalCode = PostalCode.Trim().ToUpper(); } else { PostalCode = PostalCode.Trim().ToUpper(); } } else { yield return(new ValidationResult("Invalid postal code. Postal code must match Canadian postal pattern", new[] { "PostalCode" })); } } Regex homePhoneRegex = new Regex(@"^[0-9]{3}-{0,1}[0-9]{3}-{0,1}[0-9]{4}"); if (HomePhone != null) { if (homePhoneRegex.IsMatch(HomePhone)) { if (!HomePhone.Contains('-')) { HomePhone = HomePhone.Insert(3, "-"); HomePhone = HomePhone.Insert(7, "-"); HomePhone = HomePhone.Trim(); } } else { yield return(new ValidationResult("Invalid Phone Number Format. It must be in the format : 999-999-9999", new[] { "HomePhone" })); } } if (string.IsNullOrEmpty(SpouseFirstName) && string.IsNullOrEmpty(SpouseLastName)) { FullName = LastName.Trim() + ", " + FirstName.Trim(); } else { if (SpouseLastName == null || SpouseLastName == LastName) { FullName = LastName.Trim() + ", " + FirstName.Trim() + " & " + SpouseFirstName.Trim(); } else { FullName = LastName.Trim() + ", " + FirstName.Trim() + " & " + SpouseLastName.Trim() + ", " + SpouseFirstName.Trim(); } } if (UseCanadaPost) { if (string.IsNullOrEmpty(Street)) { yield return(new ValidationResult("If Canada post is checked, street name is required", new[] { "Street" })); } if (string.IsNullOrEmpty(City)) { yield return(new ValidationResult("If Canada post is checked, city name is required", new[] { "City" })); } } else { if (string.IsNullOrEmpty(Email)) { yield return(new ValidationResult("If Canada post is not checked, email address is required", new[] { "Email" })); } } if (Street != null) { Street = Street.Trim(); } if (City != null) { City = City.Trim(); } if (Email != null) { Email = Email.Trim(); } if (Comment != null) { Comment = Comment.Trim(); } if (LastName != null) { LastName = LastName.Trim(); } if (FirstName != null) { FirstName = FirstName.Trim(); } if (SpouseFirstName != null) { SpouseFirstName = SpouseFirstName.Trim(); } if (SpouseLastName != null) { SpouseLastName = SpouseLastName.Trim(); } //determine if editing or creating new var memberId = _context.Member.Where(x => x.MemberId == MemberId).FirstOrDefault(); if (memberId != null) { //yield error : member id is already on file } else { //yield error: member id not on file } yield return(ValidationResult.Success); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { //if (MemberId != 0) //{ // FullName = FirstName + ' ' + LastName + " & " + SpouseFirstName; //} if (ProvinceCode != null) { if (ProvinceCode.Length != 2) { yield return(new ValidationResult("The Province Code should be exactly 2 characters long", new[] { "ProvinceCode" })); } else { var province = _context.Province.Where(m => m.ProvinceCode == ProvinceCode).FirstOrDefault(); if (province == null) { yield return(new ValidationResult("The Province Code is not valid", new[] { "ProvinceCode" })); } else { ProvinceCode = ProvinceCode.Trim().ToUpper(); } } } Regex PostalCodePattern = new Regex((@"^[a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}\s{0,1}[0-9]{1}[a-zA-Z]{1}[0-9]{1}"), RegexOptions.IgnoreCase); if (PostalCodePattern.IsMatch(PostalCode.Trim())) { if (!PostalCode.Contains(" ")) { PostalCode = PostalCode.Insert(3, " "); PostalCode = PostalCode.Trim().ToUpper(); } else { PostalCode = PostalCode.Trim().ToUpper(); } } else { yield return(new ValidationResult("The Postal Code entered is not in valid canadian format", new[] { "PostalCode" })); } Regex HomePhonePattern = new Regex(@"^\d\d\d-{0,1}\d\d\d-{0,1}\d\d\d\d"); if (HomePhone != null) { if (HomePhonePattern.IsMatch(HomePhone)) { if (!HomePhone.Contains('-')) { HomePhone = HomePhone.Insert(3, "-"); HomePhone = HomePhone.Insert(7, "-"); HomePhone = HomePhone.Trim(); } } else { yield return(new ValidationResult("The home Phone number entered is not in valid format 999-999-9999", new[] { "HomePhone" })); } } if (string.IsNullOrEmpty(SpouseFirstName) && string.IsNullOrEmpty(SpouseLastName)) { FullName = LastName.Trim() + "," + FirstName.Trim(); } else { if (SpouseLastName == null || SpouseLastName == LastName) { FullName = FirstName.Trim() + ' ' + LastName.Trim() + " & " + SpouseFirstName.Trim(); } else { FullName = LastName.Trim() + "," + FirstName.Trim() + " & " + SpouseLastName.Trim() + "," + SpouseFirstName.Trim(); } } if (UseCanadaPost) { if (string.IsNullOrEmpty(Street) && string.IsNullOrEmpty(City)) { yield return(new ValidationResult("The Street name and City Name field are required fields if you have checked Canada Post checkbox", new[] { "Street" })); } } else { if (string.IsNullOrEmpty(Email)) { yield return(new ValidationResult("The Email address field is required", new[] { "Email" })); } } if (MemberId == 0) { var duplicateID = _context.Member.Where(x => x.MemberId == MemberId).FirstOrDefault(); if (duplicateID != null) { yield return(new ValidationResult("The Member Id entered is already on file", new[] { "MemberId" })); } } if (Street != null) { Street = Street.Trim(); } if (City != null) { City = City.Trim(); } if (Email != null) { Email = Email.Trim(); } if (Comment != null) { Comment = Comment.Trim(); } yield return(ValidationResult.Success); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (FirstName == null || FirstName.Trim() == "") { yield return(new ValidationResult("First name cannot be empty or blank.")); } else { FirstName = FirstName.Trim(); FirstName = ATValidations.ATCapitalize(FirstName); } if (LastName == null || LastName.Trim() == "") { yield return(new ValidationResult("Last name cannot be empty or blank.")); } else { LastName = LastName.Trim(); LastName = ATValidations.ATCapitalize(LastName); } if (Address == null || Address.Trim() == "") { yield return(new ValidationResult("Address cannot be empty or blank.")); } else { Address = ATValidations.ATCapitalize(Address); } if (City == null || City.Trim() == "") { yield return(new ValidationResult("City cannot be empty or blank.")); } else { City = ATValidations.ATCapitalize(City); } if (Gender == null || Gender.Trim() == "") { yield return(new ValidationResult("Gender cannot be empty or blank.")); } else { Gender = ATValidations.ATCapitalize(Gender); } if (ProvinceCode.Length > 2) { yield return(new ValidationResult("Province code cannot be more than 2 letters.")); } //if (!string.IsNullOrEmpty(PostalCode)){ // var provinceName = _context.Diagnosis.Where(a => a.DiagnosisId == patDiagnosisRecord.DiagnosisId).FirstOrDefault(); // PostalCode = PostalCode.ToUpper(); // if (string.IsNullOrEmpty(ProvinceCode)) // { // yield return new ValidationResult("Province code is needed first", new[] { "Postalcode" }); // } // if(corres) //} if (!string.IsNullOrEmpty(Ohip)) { Ohip = Ohip.Trim().ToUpper(); Regex ohipRegex = new Regex(@"\d{4}(-\d{3})(-\d{3})-[A-Z][A-Z]", RegexOptions.IgnoreCase); if (!ohipRegex.IsMatch(Ohip)) { yield return(new ValidationResult("OHIP pattern is 1111-111-111-XX", new[] { "Ohip" })); } } if (!string.IsNullOrEmpty(HomePhone)) { HomePhone = ATValidations.ATExtractDigits(HomePhone); if (HomePhone.Length != 10) { yield return(new ValidationResult("Please enter 10 digits for Phone number", new[] { "HomePhone" })); } else { HomePhone = HomePhone.Insert(3, "-").Insert(7, "-"); } } if (DateOfBirth.HasValue) { if (DateOfBirth.Value.Date > DateTime.Now.Date) { yield return(new ValidationResult("Date of birth cannot be future date", new[] { "DateOfBirth" })); } if (Deceased) { if (!DateOfDeath.HasValue) { yield return(new ValidationResult("Please enter the Date of Death", new[] { "DateOfDeath" })); } } else { if (DateOfDeath.HasValue) { yield return(new ValidationResult("Date of Death should be empty", new[] { "DateOfDeath" })); } } if (DateOfDeath.HasValue) { if (DateOfDeath.Value.Date > DateTime.Now.Date || DateOfDeath.Value.Date < DateOfBirth.Value.Date) { yield return(new ValidationResult("Date of Death cannot be in the future or before date of birth", new[] { "DateOfDeath" })); } } } if (!string.IsNullOrEmpty(Gender)) { Gender = Gender.ToUpper(); Regex genderRegex = new Regex("[MFX]"); if (!genderRegex.IsMatch(Gender)) { yield return(new ValidationResult("Gender is required and must be 'M', 'F' or 'X'", new[] { "Gender" })); } } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { //First Name check and Capitalize if (string.IsNullOrEmpty(FirstName)) { yield return(new ValidationResult("Requir First Name", new[] { "FirstName" })); } else { FirstName = KYValidations.KYCapitalize(FirstName); } //Last Name Check and Capitalize if (string.IsNullOrEmpty(LastName)) { yield return(new ValidationResult("Requir Last Name", new[] { "LastName" })); } else { LastName = KYValidations.KYCapitalize(LastName); } // Address Capitalize Address = KYValidations.KYCapitalize(Address); // City Capitalize City = KYValidations.KYCapitalize(City); // Province Code Check Province findProvinceinDatadabase = null; if (!string.IsNullOrEmpty(ProvinceCode)) { ProvinceCode = ProvinceCode.ToUpper(); string err = string.Empty; try { findProvinceinDatadabase = _context.Province.Where(a => a.ProvinceCode == ProvinceCode).FirstOrDefault(); } catch (Exception e) { err = e.GetBaseException().Message; } if (findProvinceinDatadabase == null) { yield return(new ValidationResult("Province Code is not on file", new[] { "ProvinceCode" })); } if (!string.IsNullOrEmpty(err)) { yield return(new ValidationResult(err, new[] { "ProvinceCode" })); } } //postalcode check and format if (!string.IsNullOrEmpty(PostalCode)) { if (string.IsNullOrEmpty(ProvinceCode)) { yield return(new ValidationResult("Province Code is required to validate Postal Code", new[] { "ProvinceCode", "PostalCode" })); } if (findProvinceinDatadabase != null) { if (findProvinceinDatadabase.CountryCode == "CA") { //if (!PostalCode.StartsWith(findProvinceinDatadabase.FirstPostalLetter)) // yield return new ValidationResult("First letter of Postal Code not valid for given province", new[] { "ProvinceCode", "PostalCode", "" }); if (KYValidations.KYPostalCodeValidation(PostalCode)) { PostalCode = KYValidations.KYPostalCodeFormat(PostalCode); } else { yield return(new ValidationResult("Postal Code not CDN pattern: A3A 3A3", new[] { "PostalCode" })); } } else if (findProvinceinDatadabase.CountryCode == "USA") { string localPostalCode = PostalCode; if (KYValidations.KYZipCodeValidation(ref localPostalCode)) { PostalCode = localPostalCode; } else { yield return(new ValidationResult("Zip Code is not valid", new[] { "PostalCode" })); } } } } //OHIP check if (!string.IsNullOrEmpty(Ohip)) { Ohip = Ohip.ToUpper().Trim(); Regex OhipValidate = new Regex(@"^\d{4}-\d{3}-\d{3}-[A-Z][A-Z]$"); if (!OhipValidate.IsMatch(Ohip)) { yield return(new ValidationResult("OHIP. if provided, must match pattern: 1234-123-123-XX", new[] { "Ohip" })); } } //Date of Birth check if (DateOfBirth != null) { if (DateOfBirth > DateTime.Now) { yield return(new ValidationResult("Date of Birth cannot be in the future", new[] { "DateOfBirth" })); } } // Date of Death check string popupMessage = string.Empty; if (Deceased) { if (DateOfDeath == null) { popupMessage = "Deceased must be true if Date of Death is provided"; yield return(new ValidationResult(popupMessage, new[] { "DateOfDeath" })); } else if (DateOfDeath > DateTime.Now) { popupMessage = "Date of Death cannot be in the future"; yield return(new ValidationResult(popupMessage, new[] { "DateOfDeath" })); } else if (DateOfDeath < DateOfBirth) { popupMessage = "Date of Death cannot be before Date of Birth"; yield return(new ValidationResult(popupMessage, new[] { "DateOfDeath", "DateOfBirth" })); } } else { if (DateOfDeath != null) { popupMessage = "Deceased must be true if Date of Death is provided"; yield return(new ValidationResult(popupMessage, new[] { "Deceased" })); } if (DateOfDeath != null && DateOfDeath > DateTime.Now) { popupMessage = "Date of Death cannot be in the future"; yield return(new ValidationResult(popupMessage, new[] { "DateOfDeath" })); } } //Phone check if (!string.IsNullOrEmpty(HomePhone)) { HomePhone = HomePhone.Trim(); HomePhone = KYValidations.KYExtractDigits(HomePhone); if (HomePhone.Length != 10) { yield return(new ValidationResult("Home Phone, if provided, must be 10 digits: 123-123-1234", new[] { "HomePhone" })); } else { HomePhone = HomePhone.Insert(3, "-"); HomePhone = HomePhone.Insert(7, "-"); } } //Gender Check and Capitalize if (string.IsNullOrEmpty(Gender)) { yield return(new ValidationResult("Requir Gender", new[] { "Gender" })); } else { string lowerGender = Gender.Trim().ToLower();; if (lowerGender != "m" && lowerGender != "f" && lowerGender != "x") { yield return(new ValidationResult("Gender must be either 'M', 'F' or 'X'", new[] { "Gender" })); } else { Gender = KYValidations.KYCapitalize(Gender); } } yield return(ValidationResult.Success); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { //trim all strings //DateOfDeath, DateOfBirth are not trimmed because they are not string //first name process if (string.IsNullOrEmpty(FirstName)) { yield return(new ValidationResult("First Name is required", new[] { "FirstName" })); } else { FirstName = FirstName.Trim(); FirstName = AYValidation.AYCapitalize(FirstName); } if (string.IsNullOrEmpty(LastName)) { yield return(new ValidationResult("last Name is required", new[] { "LastName" })); } else { LastName = LastName.Trim(); LastName = AYValidation.AYCapitalize(LastName); } Regex genderPattern = new Regex(@"^[MFXmfx]$"); if (string.IsNullOrEmpty(Gender)) { yield return(new ValidationResult("Gender is required", new[] { "Gender" })); } else if (genderPattern.IsMatch(Gender)) { Gender = AYValidation.AYCapitalize(Gender); } else { yield return(new ValidationResult("Gender is among: M, F, X", new[] { "Gender" })); } Address = AYValidation.AYCapitalize(Address).Trim(); City = AYValidation.AYCapitalize(City).Trim(); Province correspondingProvince = null; if (!string.IsNullOrEmpty(ProvinceCode)) { ProvinceCode = ProvinceCode.Trim().ToUpper(); string err = string.Empty; try { correspondingProvince = _context.Province.Where(a => a.ProvinceCode == ProvinceCode).FirstOrDefault(); } catch (Exception ex) { err = ex.GetBaseException().Message; } if (correspondingProvince == null) { yield return(new ValidationResult("Province Code not on the list", new[] { "ProvinceCode" })); } if (!string.IsNullOrEmpty(err)) { yield return(new ValidationResult(err, new[] { "ProvinceCode" })); } } if (!string.IsNullOrEmpty(PostalCode)) { if (string.IsNullOrEmpty(ProvinceCode)) { yield return(new ValidationResult("Province Code is needed first", new[] { "PostalCode" })); } if (correspondingProvince != null) //countrycode could be US or CA { if (correspondingProvince.CountryCode == "CA") { Regex firstLetterPattern = new Regex("^[" + correspondingProvince.FirstPostalLetter + "]$"); if (!firstLetterPattern.IsMatch(PostalCode.Substring(0, 1))) { yield return(new ValidationResult("Postal Code is not correct for that Province", new[] { "ProvinceCode", "PostalCode" })); } else { if (AYValidation.AYPostalCodeValidation(PostalCode)) { PostalCode = AYValidation.AYPostalCodeFormat(PostalCode); } else { yield return(new ValidationResult("Postal Code is not correct.", new[] { "PostalCode" })); } } } } } if (!string.IsNullOrEmpty(Ohip)) { Ohip = Ohip.Trim().ToUpper(); Regex ohipPattern = new Regex(@"^\d\d\d\d[-]\d\d\d[-]\d\d\d[-][A-Z][A-Z]$", RegexOptions.IgnoreCase); if (!ohipPattern.IsMatch(Ohip)) { yield return(new ValidationResult("Ohip should match pattern: 1234-123-123-XX", new[] { "Ohip" })); } } if (!string.IsNullOrEmpty(HomePhone)) { HomePhone = AYValidation.AYExtractDigits(HomePhone); if (HomePhone.Length != 10) { yield return(new ValidationResult("Home phone should be 10 digits", new[] { "HomePhone" })); } else { HomePhone = HomePhone.Insert(3, "-").Insert(7, "-"); } } if (DateOfBirth != null) //dateofbirth is not string { if (DateOfBirth > DateTime.Now) { yield return(new ValidationResult("Date of birth is not correct", new[] { "DateOfBirth" })); } } if (Deceased) { if (DateOfDeath == null) { yield return(new ValidationResult("Please enter date of death", new[] { "DateOfBirth" })); } if (DateOfDeath > DateTime.Now || DateOfDeath > DateTime.Now) { yield return(new ValidationResult("Please enter correct date of death", new[] { "DateOfBirth" })); } } else { if (DateOfDeath != null) { yield return(new ValidationResult("Don' enter date of death if not deceased", new[] { "DateOfDeath" })); } } yield return(ValidationResult.Success); }