Ejemplo n.º 1
0
        public bool CanProceedWithThisAddress()
        {
            if (!AddressLineOne.HasValue() && RequiredAddr())
            {
                modelState.AddModelError(Parent.GetNameFor(mm => mm.List[Index].AddressLineOne), "address required.");
            }
            if (RequiredZip() && !ZipCode.HasValue() && !RequiredAddr())
            {
                modelState.AddModelError(Parent.GetNameFor(mm => mm.List[Index].ZipCode), "zip required.");
            }

            if (!RequiredZip() || !AddressLineOne.HasValue())
            {
                return(true);
            }

            var hasCityStateOrZip = (City.HasValue() && State.HasValue()) || ZipCode.HasValue();

            if (!hasCityStateOrZip)
            {
                modelState.AddModelError(Parent.GetNameFor(mm => mm.List[Index].ZipCode), "zip required (or \"na\")");
            }

            if (!modelState.IsValid)
            {
                Log("AddressNotValid");
                return(false);
            }
            var countryIsOK = modelState.IsValid && AddressLineOne.HasValue() && (Country == "United States" || !Country.HasValue());

            if (!countryIsOK)
            {
                return(true); // not going to validate address
            }
            var r = AddressVerify.LookupAddress(AddressLineOne, AddressLineTwo, City, State, ZipCode);

            if (r.Line1 == "error")
            {
                return(true); // Address Validator is not available, skip check
            }
            if (r.found == false)
            {
                return(true); // not going to bother them to ask for better address
            }
            // populate Address corrections
            if (r.Line1 != AddressLineOne)
            {
                AddressLineOne = r.Line1;
            }
            if (r.Line2 != (AddressLineTwo ?? ""))
            {
                AddressLineTwo = r.Line2;
            }
            if (r.City != (City ?? ""))
            {
                City = r.City;
            }
            if (r.State != (State ?? ""))
            {
                State = r.State;
            }
            if (r.Zip != (ZipCode ?? ""))
            {
                ZipCode = r.Zip;
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void ValidateModelForNew(ModelStateDictionary ModelState, int i)
        {
            var dobname     = Parent.GetNameFor(mm => mm.List[i].DateOfBirth);
            var foundname   = Parent.GetNameFor(mm => mm.List[i].Found);
            var isnewfamily = whatfamily == 3;

            ValidBasic(ModelState, i);
            DateTime dt;

            if (RequiredDOB() && DateOfBirth.HasValue() && !Util.BirthDateValid(bmon, bday, byear, out dt))
            {
                ModelState.AddModelError(dobname, "birthday invalid");
            }
            else if (!birthday.HasValue && RequiredDOB())
            {
                ModelState.AddModelError(dobname, "birthday required");
            }
            if (birthday.HasValue && NoReqBirthYear() == false && birthday.Value.Year == Util.SignalNoYear)
            {
                ModelState.AddModelError(dobname, "BirthYear is required");
                IsValidForNew = false;
                return;
            }

            var minage = DbUtil.Db.Setting("MinimumUserAge", "16").ToInt();

            if (orgid == Util.CreateAccountCode && age < minage)
            {
                ModelState.AddModelError(dobname, "must be {0} to create account".Fmt(minage));
            }

            if (ComputesOrganizationByAge() && GetAppropriateOrg() == null)
            {
                ModelState.AddModelError(dobname, NoAppropriateOrgError);
            }

            ValidateBirthdayRange(ModelState, i);
            int n = 0;

            if (Phone.HasValue() && Phone.GetDigits().Length >= 10)
            {
                n++;
            }
            if (ShowAddress && HomePhone.HasValue() && HomePhone.GetDigits().Length >= 10)
            {
                n++;
            }

            if (RequiredPhone() && n == 0)
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].Phone), "cell or home phone required");
            }

            if (HomePhone.HasValue() && HomePhone.GetDigits().Length > 20)
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].HomePhone), "homephone too long");
            }

            if (EmailAddress.HasValue())
            {
                EmailAddress = EmailAddress.Trim();
            }
            if (!EmailAddress.HasValue() || !Util.ValidEmail(EmailAddress))
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].EmailAddress), "Please specify a valid email address.");
            }
            if (isnewfamily)
            {
                if (!AddressLineOne.HasValue() && RequiredAddr())
                {
                    ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].AddressLineOne), "address required.");
                }
                if (RequiredZip() && AddressLineOne.HasValue())
                {
                    var addrok = City.HasValue() && State.HasValue();
                    if (ZipCode.HasValue())
                    {
                        addrok = true;
                    }
                    if (!addrok)
                    {
                        ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].ZipCode), "zip required (or \"na\")");
                    }

                    if (ModelState.IsValid && AddressLineOne.HasValue() &&
                        (Country == "United States" || !Country.HasValue()))
                    {
                        var r = AddressVerify.LookupAddress(AddressLineOne, AddressLineTwo, City, State, ZipCode);
                        if (r.Line1 != "error")
                        {
                            if (r.found == false)
                            {
                                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].ZipCode), r.address + ", to skip address check, Change the country to USA, Not Validated");
                                ShowCountry = true;
                                return;
                            }
                            if (r.Line1 != AddressLineOne)
                            {
                                AddressLineOne = r.Line1;
                            }
                            if (r.Line2 != (AddressLineTwo ?? ""))
                            {
                                AddressLineTwo = r.Line2;
                            }
                            if (r.City != (City ?? ""))
                            {
                                City = r.City;
                            }
                            if (r.State != (State ?? ""))
                            {
                                State = r.State;
                            }
                            if (r.Zip != (ZipCode ?? ""))
                            {
                                ZipCode = r.Zip;
                            }
                        }
                    }
                }
            }

            if (!gender.HasValue && RequiredGender())
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].gender), "Please specify gender");
            }
            if (!married.HasValue && RequiredMarital())
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].married), "Please specify marital status");
            }

            if (MemberOnly())
            {
                ModelState.AddModelError(foundname, "Sorry, must be a member of church");
            }
            else if (org != null && setting.ValidateOrgIds.Count > 0)
            {
                ModelState.AddModelError(foundname, "Must be member of specified organization");
            }

            IsValidForNew      = ModelState.IsValid;
            IsValidForContinue = ModelState.IsValid;
        }