public void SetDefaultCasing()
 {
     if (Line1 != null)
     {
         Line1 = Line1.ToInvariantTitleCase();
     }
     if (Line2 != null)
     {
         Line2 = Line2.ToInvariantTitleCase();
     }
     if (StateOrProvince != null)
     {
         StateOrProvince = StateOrProvince.ToInvariantTitleCase();
     }
     if (PostalCode != null)
     {
         PostalCode = PostalCode.ToUpper();
     }
     if (City != null)
     {
         City = City.ToInvariantTitleCase();
     }
     if (CountryCode != null)
     {
         CountryCode = CountryCode.ToUpper();
     }
 }
示例#2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            FirstName = BPValidations.Capitalise(FirstName);
            LastName  = BPValidations.Capitalise(LastName);
            FullName  = LastName + "," + FirstName;

            if (ProvinceCode != null)
            {
                ProvinceCode = ProvinceCode.ToUpper();
            }
            if (PostalCode != null)
            {
                PostalCode = PostalCode.ToUpper();
                if (PostalCode[3] != ' ')
                {
                    PostalCode = PostalCode.Insert(3, " ");
                }
            }

            //HomePhone and WorkPhone Validation
            HomePhone = BPValidations.FormatPhoneNumber(HomePhone);
            if (WorkPhone != null)
            {
                WorkPhone = BPValidations.FormatPhoneNumber(WorkPhone);
            }

            yield return(ValidationResult.Success);
        }
示例#3
0
 private void formatPostalCode()
 {
     PostalCode.ToUpper();
     if (PostalCode.Length > 6)
     {
         PostalCode.Replace('-', ' ');
     }
     else
     {
         PostalCode.Insert(3, " ");
     }
 }
示例#4
0
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     FirstName    = MKValidation.Capitalise(FirstName);
     LastName     = MKValidation.Capitalise(LastName);
     FullName     = LastName + ", " + FirstName;
     HomePhone    = Phoneverification(HomePhone);
     WorkPhone    = Phoneverification(WorkPhone);
     ProvinceCode = ProvinceCode.ToUpper();
     PostalCode   = PostalCode.ToUpper();
     if (PostalCode.Length == 6)
     {
         PostalCode = PostalCode.Insert(3, " ");
     }
     yield return(ValidationResult.Success);
 }
示例#5
0
        public override bool MatchFilter(string filter)
        {
            string ucfilter = filter.ToUpper();

            if (base.MatchFilter(filter) == true)
            {
                return(true);
            }
            else if (Name.ToUpper().Contains(ucfilter))
            {
                return(true);
            }
            else if (CustomerID.ToString().Contains(filter))
            {
                return(true);
            }
            else if (AccountNumber.ToUpper().Contains(ucfilter))
            {
                return(true);
            }
            else if (Address.ToUpper().Contains(ucfilter))
            {
                return(true);
            }
            else if (City.ToUpper().Contains(ucfilter))
            {
                return(true);
            }
            else if (Province.ToUpper().Contains(ucfilter))
            {
                return(true);
            }
            else if (PostalCode.ToUpper().Contains(ucfilter))
            {
                return(true);
            }
            else if (Customer.Name.ToUpper().Contains(ucfilter))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#6
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            _context = new ClubsContext();  //requires code somewhere else

            //var _context = validationContext.GetService<ClubsContext>(); // requires dependencyinjection

            // all strings that are null become empty and trim all
            if (FirstName == null)
            {
                FirstName = "";
            }
            FirstName = FirstName.Trim();
            if (LastName == null)
            {
                LastName = "";
            }
            LastName = LastName.Trim();
            if (CompanyName == null)
            {
                CompanyName = "";
            }
            CompanyName = CompanyName.Trim();
            if (StreetAddress == null)
            {
                StreetAddress = "";
            }
            StreetAddress = StreetAddress.Trim();
            if (PostalCode == null)
            {
                PostalCode = "";
            }
            PostalCode = PostalCode.Trim();
            if (ProvinceCode == null)
            {
                ProvinceCode = "";
            }
            ProvinceCode = ProvinceCode.Trim();
            if (Email == null)
            {
                Email = "";
            }
            Email = Email.Trim();
            if (Phone == null)
            {
                Phone = "";
            }
            Phone = Phone.Trim();

            // use our prebuilt string manipulators to capitalize and extract digits
            FirstName     = SDStringManipulation.SDCapitalize(FirstName);
            LastName      = SDStringManipulation.SDCapitalize(LastName);
            CompanyName   = SDStringManipulation.SDCapitalize(CompanyName);
            StreetAddress = SDStringManipulation.SDCapitalize(StreetAddress);
            City          = SDStringManipulation.SDCapitalize(City);

            Phone = SDStringManipulation.SDExtractDigits(Phone);

            if (FirstName == "" && LastName == "" && CompanyName == "")
            {
                yield return(new ValidationResult("You must enter either First Name, Last Name, or Company Name."));
            }

            if (ProvinceCode != "")
            {
                var province = _context.Province.Where(a => a.ProvinceCode.ToLower() == ProvinceCode.ToLower()).FirstOrDefault(); // pull province
                if (province == null)
                {
                    yield return(new ValidationResult("The Province Code must be an existing province code within our database. Good luck figuring them out lol", new string[] { nameof(ProvinceCode) }));
                }
                else
                {
                    ProvinceCode = ProvinceCode.ToUpper(); // to save nicely

                    var country = _context.Country.Where(a => a.CountryCode == province.CountryCode).FirstOrDefault();
                    if (PostalCode != "")
                    {
                        if (!SDStringManipulation.SDPostalCodeIsValid(PostalCode.ToUpper(), country.PostalPattern)) // runs the postal through the regex for the country's postal pattern
                        {
                            yield return(new ValidationResult("The postal code must match the country's format", new string[] { nameof(PostalCode) }));
                        }

                        if (country.Name == "Canada")
                        {
                            PostalCode = PostalCode.ToUpper(); // you would be ashamed of how long I was stuck here before realizing the regex was case sensitive (and that we should be storing them as capitals anyway)
                            if (PostalCode != "")
                            {
                                char firstLetter = PostalCode[0];
                                if (!province.FirstPostalLetter.Contains(firstLetter)) // checks against the saved first letters for province postal codes
                                {
                                    yield return(new ValidationResult("The postal code must match the province's postal codes.", new string[] { nameof(PostalCode) }));
                                }
                            }
                        }
                        if (PostalCode.Length > 6)
                        {
                            PostalCode.Insert(3, " ");
                        }
                    }
                }
            }

            if (Email == "")
            {
                if (StreetAddress == "" || City == "" || PostalCode == "" || ProvinceCode == "")
                {
                    yield return(new ValidationResult("You must submit either a valid email or all postal information."));
                }
            }

            Regex regPhone = new Regex(@"^[0-9]{10}$"); // upon coming back I realize I basically did this in my string manipulation and just have to check length

            // but hey it tests length too and I am just super done with this :)
            if (Phone == "")
            {
                yield return(new ValidationResult("Please enter a valid phone number.", new string[] { nameof(Phone) }));
            }
            else if (!regPhone.IsMatch(Phone))
            {
                yield return(new ValidationResult("Please enter a 10 digit phone number.", new string[] { nameof(Phone) }));
            }
            else
            {
                Phone = Phone.Insert(3, "-");
                Phone = Phone.Insert(7, "-");
            }

            yield return(ValidationResult.Success);
        }
示例#7
0
        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;
            }
        }
示例#8
0
        public IEnumerable <ValidationResult> Validate(string instanceName, bool isRequired = false)
        {
            var result = new List <ValidationResult>();

            if (IsCanada())
            {
                if (string.IsNullOrWhiteSpace(Number) || string.IsNullOrWhiteSpace(Street))
                {
                    result.Add(new ValidationResult(string.Empty, new[] { $"{instanceName}.{nameof(Number)}", $"{instanceName}.{nameof(Street)}" }));
                }

                if (string.IsNullOrWhiteSpace(City))
                {
                    result.Add(new ValidationResult(string.Empty, new[] { $"{instanceName}.{nameof(City)}" }));
                }

                if (string.IsNullOrWhiteSpace(Province))
                {
                    result.Add(new ValidationResult(string.Empty, new[] { $"{instanceName}.{nameof(Province)}" }));
                }

                if (string.IsNullOrWhiteSpace(PostalCode) || !Helpers.ValidationHelper.IsPostalCodeValid(PostalCode.ToUpper()))
                {
                    result.Add(new ValidationResult(string.Empty, new[] { $"{instanceName}.{nameof(PostalCode)}" }));
                }

                if (PhoneNumberShownAndRequired)
                {
                    if (string.IsNullOrWhiteSpace(MainPhoneNumber) || !Helpers.ValidationHelper.IsPhoneNumberValid(MainPhoneNumber))
                    {
                        result.Add(new ValidationResult(string.Empty, new[] { $"{instanceName}.{nameof(MainPhoneNumber)}" }));
                    }

                    if (!string.IsNullOrWhiteSpace(SecondaryPhoneNumber) && !Helpers.ValidationHelper.IsPhoneNumberValid(SecondaryPhoneNumber))
                    {
                        result.Add(new ValidationResult(string.Empty, new[] { $"{instanceName}.{nameof(SecondaryPhoneNumber)}" }));
                    }
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(AddressOutsideCanada))
                {
                    result.Add(new ValidationResult(string.Empty, new[] { $"{instanceName}.{nameof(AddressOutsideCanada)}" }));
                }

                if (PhoneNumberShownAndRequired)
                {
                    if (string.IsNullOrWhiteSpace(PhoneNumberOutsideCanada))
                    {
                        result.Add(new ValidationResult(string.Empty, new[] { $"{instanceName}.{nameof(PhoneNumberOutsideCanada)}" }));
                    }
                }
            }

            return(result);
        }
示例#9
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            //throw new NotImplementedException();

            if (FirstName == null || FirstName.Trim() == "")
            {
                yield return(new ValidationResult("First name cannot be empty or just blanks",
                                                  new[] { nameof(FirstName) }));
            }

            if (!(FirstName == null || FirstName.Trim() == ""))
            {
                FirstName = FirstName.Trim();
            }

            if (LastName == null || LastName.Trim() == "")
            {
                yield return(new ValidationResult("Last name cannot be empty or just blanks",
                                                  new[] { nameof(LastName) }));
            }

            if (!(LastName == null || LastName.Trim() == ""))
            {
                LastName = LastName.Trim();
            }


            FirstName = KAValidations.KACapitalize(FirstName);
            LastName  = KAValidations.KACapitalize(LastName);
            Address   = KAValidations.KACapitalize(Address);
            City      = KAValidations.KACapitalize(City);
            Gender    = KAValidations.KACapitalize(Gender);


            if (!String.IsNullOrEmpty(ProvinceCode))
            {
                ProvinceCode = ProvinceCode.ToUpper();
            }


            if (!String.IsNullOrEmpty(Ohip))
            {
                Ohip = KAValidations.KACapitalize(Ohip);

                if (!KAValidations.KAOhipValidation(Ohip))
                {
                    yield return(new ValidationResult("Ohip format not accepted. Accepted format is 1234-123-123-XX",
                                                      new[] { nameof(Ohip) }));
                }
            }

            if (!String.IsNullOrEmpty(HomePhone))
            {
                string phoneDigits = KAValidations.KAExtractDigits(HomePhone);

                if (Regex.IsMatch(phoneDigits, @"^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$"))
                {
                    phoneDigits = phoneDigits.Insert(3, "-");
                    phoneDigits = phoneDigits.Insert(7, "-");



                    HomePhone = phoneDigits;
                }

                else
                {
                    yield return(new ValidationResult("Home Phone number format is wrong. Home phone number must contain exactly 10 digits",
                                                      new[] { nameof(HomePhone) }));
                }
            }


            if (!String.IsNullOrEmpty(DateOfBirth.ToString()))
            {
                if (DateOfBirth > DateTime.Now)
                {
                    yield return(new ValidationResult("Date of birth cannot be in future",
                                                      new[] { nameof(DateOfBirth) }));
                }
            }


            if (Deceased)
            {
                if (String.IsNullOrWhiteSpace(DateOfDeath.ToString()))
                {
                    yield return(new ValidationResult("Date of Death is compulsary for deceased patients",
                                                      new[] { nameof(DateOfDeath) }));
                }
            }

            if (!Deceased)
            {
                if (!String.IsNullOrWhiteSpace(DateOfDeath.ToString()))
                {
                    yield return(new ValidationResult("Cannot add date of death for patient who is not dead (deceased must be checked)",
                                                      new[] { nameof(DateOfDeath) }));
                }
            }

            if (!String.IsNullOrWhiteSpace(DateOfDeath.ToString()))
            {
                if (DateOfDeath < DateOfBirth)
                {
                    yield return(new ValidationResult("Date of death cannot be before date of birth.",
                                                      new[] { nameof(DateOfDeath) }));
                }

                if (DateOfDeath > DateTime.Now)
                {
                    yield return(new ValidationResult("Date of death cannot be in future",
                                                      new[] { nameof(DateOfDeath) }));
                }
            }

            if (String.IsNullOrWhiteSpace(Gender))
            {
                yield return(new ValidationResult("Gender is required",
                                                  new[] { nameof(Gender) }));
            }

            if (!(Gender == "M" || Gender == "F" || Gender == "X"))
            {
                yield return(new ValidationResult("Gender must be M or F or X",
                                                  new[] { nameof(Gender) }));
            }



            localPatientContext = (PatientsContext)validationContext.GetService(typeof(PatientsContext));



            if (!String.IsNullOrEmpty(ProvinceCode))
            {
                ProvinceCode = KAValidations.KACapitalize(ProvinceCode);
                //try
                //{
                if (!(localPatientContext.Province.Any(x => x.ProvinceCode == ProvinceCode)))
                {
                    yield return(new ValidationResult("This province name do not exists",
                                                      new[] { nameof(ProvinceCode) }));
                }
                //}

                //catch (Exception ex) {

                //}
            }


            if (!String.IsNullOrEmpty(PostalCode))
            {
                if (String.IsNullOrEmpty(ProvinceCode))
                {
                    yield return(new ValidationResult("In order to add/edit postal code, You need to add valid Province code ",
                                                      new[] { nameof(PostalCode), nameof(ProvinceCode) }));
                }

                PostalCode            = PostalCode.ToUpper();
                firstLetterPostalCode = PostalCode[0].ToString();
            }

            if (localPatientContext.Province.Where(x => x.ProvinceCode == ProvinceCode)
                .Select(x => x.CountryCode).FirstOrDefault() == "CA")
            {
                if (ProvinceCode.ToUpper() == "ON")
                {
                    if (!(firstLetterPostalCode == "K" || firstLetterPostalCode == "L" || firstLetterPostalCode == "M" || firstLetterPostalCode == "N" || firstLetterPostalCode == "P"))
                    {
                        yield return(new ValidationResult("Postal Code and Province Name are not matching ",
                                                          new[] { nameof(PostalCode), nameof(ProvinceCode) }));
                    }
                }

                else if (ProvinceCode.ToUpper() == "QC")

                {
                    if (!(firstLetterPostalCode == "G" || firstLetterPostalCode == "H" || firstLetterPostalCode == "J"))
                    {
                        yield return(new ValidationResult("Postal Code and Province Name are not matching ",
                                                          new[] { nameof(PostalCode), nameof(ProvinceCode) }));
                    }
                }

                else
                {
                    if (!(localPatientContext.Province.Where(x => x.ProvinceCode == ProvinceCode)
                          .Select(x => x.FirstPostalLetter).FirstOrDefault() == firstLetterPostalCode))
                    {
                        yield return(new ValidationResult("Postal Code and Province Name are not matching ",
                                                          new[] { nameof(PostalCode), nameof(ProvinceCode) }));
                    }
                }

                if (!KAValidations.KAPostalCodeValidation(PostalCode))
                {
                    yield return(new ValidationResult("The postal code is not as per the format",
                                                      new[] { nameof(PostalCode) }));
                }

                if (KAValidations.KAPostalCodeValidation(PostalCode))
                {
                    PostalCode = KAValidations.KAPostalCodeFormat(PostalCode);
                }
            }

            if (localPatientContext.Province.Where(x => x.ProvinceCode == ProvinceCode)
                .Select(x => x.CountryCode).FirstOrDefault() == "US")

            {
                if (!KAValidations.KAZipCodeValidation(PostalCode))
                {
                    yield return(new ValidationResult("The ZIP code is not as per the format",
                                                      new[] { nameof(PostalCode) }));
                }
            }


            yield return(ValidationResult.Success);
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(FirstName))
            {
                yield return(new ValidationResult("First name cannot be empty"));
            }
            if (string.IsNullOrEmpty(LastName))
            {
                yield return(new ValidationResult("Last Name cannot be empty", new[] { nameof(LastName) }));
            }
            if (FirstName != null)
            {
                FirstName = FirstName.Trim();
            }
            if (LastName != null)
            {
                LastName = LastName.Trim();
            }
            if (Address != null)
            {
                Address = Address.Trim();
            }
            if (City != null)
            {
                City = City.Trim();
            }
            if (ProvinceCode != null)
            {
                ProvinceCode = ProvinceCode.ToUpper();
            }
            if (PostalCode != null)
            {
                PostalCode = PostalCode.ToUpper();
            }
            if (DateOfBirth != null)
            {
                if (DateOfBirth > DateTime.Now)
                {
                    yield return(new ValidationResult("DateOfBirth can not be in future"));
                }
                if (DateOfDeath != null)
                {
                    if (DateOfBirth > DateOfDeath)
                    {
                        yield return(new ValidationResult("DateOfDeath can not be before DateOfBirth"));
                    }
                    if (DateOfDeath > DateTime.Now)
                    {
                        yield return(new ValidationResult("DateOfDeath can not be in future"));
                    }
                    if (Deceased == false)
                    {
                        yield return(new ValidationResult("Deceased must be checked "));
                    }
                }
            }
            if (HomePhone != null)
            {
                if (HomePhone.Length != 10)
                {
                    yield return(new ValidationResult("Homephone numbe rshould be exactly 10 numbers"));
                }
                else
                {
                    HomePhone = Regex.Replace(HomePhone.ToString(), "[^0-9]+", string.Empty);
                    HomePhone = HomePhone.ToString().Insert(3, "-").Insert(7, "-");
                }
            }



            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 just blanks",
                                                  new[] { nameof(FirstName) }));
            }
            else
            {
                FirstName = JJValidation.JJCapitalize(FirstName.Trim());
            }

            if (LastName == null || LastName.Trim() == "")
            {
                yield return(new ValidationResult("Last name cannot be empty or just blanks",
                                                  new[] { nameof(LastName) }));
            }
            else
            {
                LastName = JJValidation.JJCapitalize(LastName.Trim());
            }

            if (Gender == null || Gender.Trim() == "")
            {
                yield return(new ValidationResult("Gender cannot be empty or just blanks", new[] { nameof(Gender) }));
            }

            else if (Gender != "M" && Gender != "F" && Gender != "X" && Gender != "m" && Gender != "f" && Gender != "x")
            {
                yield return(new ValidationResult("Gender must be either 'M', 'F' or 'X'", new[] { "Gender" }));
            }

            else
            {
                Gender = JJValidation.JJCapitalize(Gender);
            }

            Address = JJValidation.JJCapitalize(Address);
            City    = JJValidation.JJCapitalize(City);



            string countryCode     = "";
            string firstPostalCode = "";

            //var patient = _context.Patient.FirstOrDefault();
            if (ProvinceCode != null)
            {
                var province = _context.Province.Where(p => p.ProvinceCode == ProvinceCode);

                if (!province.Any())
                {
                    yield return(new ValidationResult("Province Code is not on file", new[] { "ProvinceCode" }));
                }
                else
                {
                    countryCode     = province.FirstOrDefault().CountryCode;
                    firstPostalCode = province.FirstOrDefault().FirstPostalLetter;
                }
            }

            if (PostalCode != null && (ProvinceCode == null || countryCode == ""))
            {
                yield return(new ValidationResult("Province Code, if provided, is required to validate Postal Code", new[] { "ProvinceCode" }));
            }
            else if (PostalCode != null)
            {
                if (countryCode == "CA")
                {
                    if (JJValidation.JJPostalCodeValidation(PostalCode))
                    {
                        if (firstPostalCode.Contains(PostalCode.ToUpper().Substring(0, 1)))

                        //if (JJValidation.JJPostalCodeFirstChar(patient.PostalCode, patient.ProvinceCode))
                        {
                            PostalCode = JJValidation.JJPostalCodeFormat(PostalCode);
                        }
                        else
                        {
                            yield return(new ValidationResult("First letter of Postal Code is not valid for given province", new[] { "PostalCode" }));

                            yield return(new ValidationResult("Province code is not proper to first Postal Code", new[] { "ProvinceCode" }));
                        }
                    }
                    else
                    {
                        yield return(new ValidationResult("Postal Code is not code pattern: A3A 3A3", new[] { "PostalCode" }));
                    }
                }
                else
                {
                    string postcode = PostalCode;
                    if (JJValidation.JJZipCodeValidation(ref postcode))
                    {
                        PostalCode = postcode;
                    }
                    else
                    {
                        yield return(new ValidationResult("Province Code is is not code patter: 55555 or 12345-6789", new[] { "ProvinceCode" }));
                    }
                }
            }


            if (Ohip != null && Ohip.Trim() != "")
            {
                Ohip = Ohip.ToUpper();
                if (!Regex.IsMatch(Ohip, @"^\d{4}-\d{3}-\d{3}-[a-zA-Z]{2}$"))
                {
                    yield return(new ValidationResult("OHIP, if provided, must match pattern: 1234 - 123 - 123 - XX", new[] { "Ohip" }));
                }
            }

            if (HomePhone != null && HomePhone.Trim() != "")
            {
                string digitHomePhone = "";
                digitHomePhone = JJValidation.JJExtractDigits(HomePhone);
                if (digitHomePhone.Length != 10)
                {
                    yield return(new ValidationResult("Home phone, if provided,  must be 10 digits: 123-123-1234", new[] { nameof(HomePhone) }));
                }
                else
                {
                    HomePhone = digitHomePhone.Substring(0, 3) + "-" + digitHomePhone.Substring(3, 3) + "-" + digitHomePhone.Substring(6);
                }
            }

            if (DateOfBirth != null)
            {
                if (DateOfBirth > DateTime.Now)
                {
                    yield return(new ValidationResult("Date of Birth cannot be in the future", new[] { nameof(DateOfBirth) }));
                }
            }

            if (DateOfDeath != null)
            {
                if (DateOfDeath > DateTime.Now)
                {
                    yield return(new ValidationResult("Date of Death cannot be in the future", new[] { nameof(DateOfDeath) }));
                }
            }

            if (Deceased == true && DateOfDeath == null)
            {
                yield return(new ValidationResult("If Deceased is true, a Date Of Death is required", new[] { nameof(DateOfDeath) }));
            }
            else if (Deceased == false && DateOfDeath != null)
            {
                yield return(new ValidationResult("Deceased must be true if Date Of Death is provided", new[] { nameof(Deceased) }));
            }

            yield return(ValidationResult.Success);
        }
示例#12
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            //Use your XXStringManipulation.Capitalize method to capitalise FirstName, LastName, CompanyName, StreetAddress, and City.
            if (String.IsNullOrEmpty(FirstName))
            {
                FirstName = "";
            }
            else
            {
                FirstName = ERStringManipulation.ERCapitalize(FirstName);
            }

            if (String.IsNullOrEmpty(LastName))
            {
                LastName = "";
            }
            else
            {
                LastName = ERStringManipulation.ERCapitalize(LastName);
            }

            if (String.IsNullOrEmpty(CompanyName))
            {
                CompanyName = "";
            }
            else
            {
                CompanyName = ERStringManipulation.ERCapitalize(CompanyName);
            }

            if (String.IsNullOrEmpty(StreetAddress))
            {
                StreetAddress = "";
            }
            else
            {
                StreetAddress = ERStringManipulation.ERCapitalize(StreetAddress);
            }

            if (String.IsNullOrEmpty(City))
            {
                City = "";
            }
            else
            {
                City = ERStringManipulation.ERCapitalize(City);
            }

            //Use your XXStringManipulation.XXExtractDigits to reduce phone to just digits
            Phone = ERStringManipulation.ERExtractDigits(Phone);
            if (String.IsNullOrEmpty(Phone) || Phone.Length != 10)
            {
                yield return(new ValidationResult("Phone is required", new[] { nameof(Phone) }));
            }
            else
            {
                string newPhone = Phone.Substring(0, 3) + "-" + Phone.Substring(3, 3) + "-" + Phone.Substring(6, 4);
                Phone = newPhone;
            }


            //At least one of FirstName, LastName or CompanyName must be specified.  All can be specified, but is not mandatory.
            if (FirstName == "" && LastName == "" && CompanyName == "")
            {
                yield return(new ValidationResult("Either first name, last name or company is reuired", new[] { nameof(FirstName), nameof(LastName), nameof(CompanyName) }));
            }

            //Email Validations
            if (String.IsNullOrEmpty(Email) && String.IsNullOrEmpty(PostalCode) && String.IsNullOrEmpty(ProvinceCode) &&
                String.IsNullOrEmpty(StreetAddress) && String.IsNullOrEmpty(City))
            {
                yield return(new ValidationResult("Either Email or Postal addressing is required", new[] { nameof(Email), nameof(PostalCode), nameof(ProvinceCode),
                                                                                                           nameof(StreetAddress), nameof(City) }));
            }

            //Province code validation
            _context = new ERClubsContext();
            string foundProvince = "";
            string provinceError = "";

            if (!String.IsNullOrEmpty(ProvinceCode))
            {
                try
                {
                    var provinceCode = _context.Province.ToList();
                    foundProvince = provinceCode.FirstOrDefault(x => x.ProvinceCode == ProvinceCode).ToString();
                    if (String.IsNullOrEmpty(foundProvince))
                    {
                        //Provinc code wasnt found
                        provinceError = new ValidationResult("Province was not found", new[] { nameof(ProvinceCode) }).ToString();
                    }
                }
                catch (Exception ex)
                {
                    //Error fetching province code
                    provinceError = new ValidationResult("Error finding the province", new[] { ex.Message.ToString() }).ToString();
                }
                if (provinceError != "")
                {
                    yield return(new ValidationResult(provinceError));
                }
            }

            string postalError = "";

            //Postal code validation
            if (!String.IsNullOrEmpty(PostalCode))
            {
                //If postal provided check for province
                if (String.IsNullOrEmpty(ProvinceCode))
                {
                    yield return(new ValidationResult("Province Code is is required", new[] { nameof(ProvinceCode) }));
                }
                //Fetches the country and its postal pattern
                try
                {
                    // var foundProvinceCode = _context.Province.ToList();
                    var foundProvinceCode = _context.Province.FirstOrDefault(x => x.ProvinceCode == ProvinceCode);
                    var countryCode       = _context.Country.FirstOrDefault(x => x.CountryCode == foundProvinceCode.CountryCode.ToString());

                    string postalRegex = countryCode.PostalPattern;

                    //Changes everything to upp case
                    PostalCode = PostalCode.ToUpper();
                    //Checks if the postal is from canada
                    if (countryCode.CountryCode == "CA")
                    {
                        string firstPostal = foundProvinceCode.FirstPostalLetter;
                        if (!firstPostal.Contains(PostalCode[0]))
                        {
                            postalError = new ValidationResult("First letter of postal doesnt match the province", new[] { nameof(PostalCode) }).ToString();
                        }
                        else
                        {
                            //If no space was there adds one
                            if (PostalCode.Length == 6)
                            {
                                PostalCode = PostalCode.Insert(3, " ");
                            }
                        }
                    }

                    //Validates the postal pattern
                    if (!ERStringManipulation.ERPostalCodeIsValid(PostalCode, postalRegex))
                    {
                        postalError = new ValidationResult("Postal Code is not in correct format", new[] { nameof(PostalCode) }).ToString();
                    }
                }
                catch (Exception ex)
                {
                    postalError = new ValidationResult("Error finding the country", new[] { ex.Message.ToString() }).ToString();
                }
                if (postalError != "")
                {
                    yield return(new ValidationResult(postalError));
                }
            }
            yield return(ValidationResult.Success);
        }