Exemple #1
0
        internal void AddPerson(int originid, int?entrypointid, int?campusid)
        {
            Family f;

            if (FamilyId > 0)
            {
                f = Family;
            }
            else
            {
                f = new Family();
                AddressInfo.CopyPropertiesTo(f);
                f.ResCodeId = AddressInfo.ResCode.Value.ToInt2();
                f.HomePhone = HomePhone.GetDigits();
            }
            if (NickName != null)
            {
                NickName = NickName.Trim();
            }

            var position = DbUtil.Db.ComputePositionInFamily(Age ?? -1, MaritalStatus.Value == "20", FamilyId) ?? 10;

            FirstName = FirstName.Trim();
            if (FirstName == "na")
            {
                FirstName = "";
            }
            person = Person.Add(f, position,
                                null, FirstName.Trim(), NickName, LastName.Trim(), DOB, false, Gender.Value.ToInt(),
                                originid, entrypointid);

            this.CopyPropertiesTo(Person);
            Person.CellPhone = CellPhone.GetDigits();

            if (campusid == 0)
            {
                campusid = null;
            }
            Person.CampusId = Util.PickFirst(campusid.ToString(), DbUtil.Db.Setting("DefaultCampusId", "")).ToInt2();
            if (Person.CampusId == 0)
            {
                Person.CampusId = null;
            }

            DbUtil.Db.SubmitChanges();
            DbUtil.LogActivity("AddPerson {0}".Fmt(person.PeopleId));
            DbUtil.Db.Refresh(RefreshMode.OverwriteCurrentValues, Person);
            PeopleId = Person.PeopleId;
        }
Exemple #2
0
        public void UpdatePerson()
        {
            var p = DbUtil.Db.LoadPersonById(PeopleId);

            if (Grade == null && p.Grade == 0) // special case to fix bug
            {
                p.Grade = null;
            }

            var changes = this.CopyPropertiesTo(p);

            p.LogChanges(DbUtil.Db, changes);

            var fsb = new List <ChangeDetail>();

            p.Family.UpdateValue(fsb, "HomePhone", HomePhone.GetDigits());
            p.Family.LogChanges(DbUtil.Db, fsb, p.PeopleId, Util.UserPeopleId ?? 0);

            if (p.DeceasedDateChanged)
            {
                var ret = p.MemberProfileAutomation(DbUtil.Db);
                if (ret != "ok")
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(
                        new Exception(ret + " for PeopleId:" + p.PeopleId));
                }
            }

            DbUtil.Db.SubmitChanges();

            if (!HttpContext.Current.User.IsInRole("Access"))
            {
                changes.AddRange(fsb);
                if (changes.Count > 0)
                {
                    var np = DbUtil.Db.GetNewPeopleManagers();
                    if (np != null)
                    {
                        DbUtil.Db.EmailRedacted(p.FromEmail, np,
                                                "Basic Person Info Changed on " + Util.Host,
                                                "{0} changed the following information for {1} ({2}):<br />\n"
                                                .Fmt(Util.UserName, FirstName + " " + LastName, PeopleId)
                                                + ChangeTable(changes));
                    }
                }
            }
        }
        public void UpdatePerson(CMSDataContext db)
        {
            var p = db.LoadPersonById(PeopleId);

            if (Grade == null && p.Grade == 0) // special case to fix bug
            {
                p.Grade = null;
            }

            var changes = this.CopyPropertiesTo(p);

            p.LogChanges(db, changes);

            var fsb = new List <ChangeDetail>();

            p.Family.UpdateValue(fsb, "HomePhone", HomePhone.GetDigits());
            p.Family.LogChanges(db, fsb, p.PeopleId, db.UserPeopleId ?? 0);

            if (p.DeceasedDateChanged)
            {
                var ret = p.MemberProfileAutomation(db);
                if (ret != "ok")
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(
                        new Exception(ret + " for PeopleId:" + p.PeopleId));
                }
            }

            db.SubmitChanges();

            if (!HttpContextFactory.Current.User.IsInRole("Access"))
            {
                changes.AddRange(fsb);
                if (changes.Count > 0)
                {
                    var np = db.GetNewPeopleManagers();
                    if (np != null)
                    {
                        db.EmailRedacted(p.FromEmail, np,
                                         "Basic Person Info Changed on " + db.Host,
                                         $"{Util.UserName} changed the following information for <a href='{db.ServerLink($"/Person2/{PeopleId}")}'>{FirstName} {LastName}</a> ({PeopleId}):<br />\n"
                                         + ChangeTable(changes));
                    }
                }
            }
        }
Exemple #4
0
        public void UpdatePerson()
        {
            if (CampusId == 0)
            {
                CampusId = null;
            }
            var p   = DbUtil.Db.LoadPersonById(PeopleId);
            var psb = new StringBuilder();
            var fsb = new StringBuilder();

            p.UpdateValue(psb, "DOB", Birthday);
            p.UpdateValue(psb, "CampusId", CampusId);
            p.UpdateValue(psb, "DeceasedDate", DeceasedDate);
            p.UpdateValue(psb, "DoNotCallFlag", DoNotCallFlag);
            p.UpdateValue(psb, "DoNotMailFlag", DoNotMailFlag);
            p.UpdateValue(psb, "DoNotVisitFlag", DoNotVisitFlag);
            p.UpdateValue(psb, "DoNotPublishPhones", DoNotPublishPhones);
            p.UpdateValue(psb, "EmailAddress", PrimaryEmail.Address);
            p.UpdateValue(psb, "EmailAddress2", AltEmail.Address);
            p.UpdateValue(psb, "SendEmailAddress1", PrimaryEmail.Send);
            p.UpdateValue(psb, "SendEmailAddress2", AltEmail.Send);
            p.UpdateValue(psb, "FirstName", FirstName);
            p.UpdateValue(psb, "LastName", LastName);
            p.UpdateValue(psb, "AltName", AltName);
            p.UpdateValue(psb, "GenderId", Gender.Value.ToInt2());
            p.UpdateValue(psb, "Grade", Grade.ToInt2());
            p.UpdateValue(psb, "CellPhone", Mobile.GetDigits());
            p.Family.UpdateValue(fsb, "HomePhone", HomePhone.GetDigits());
            p.UpdateValue(psb, "MaidenName", FormerName);
            p.UpdateValue(psb, "MaritalStatusId", Marital.Value.ToInt2());
            p.UpdateValue(psb, "MiddleName", MiddleName);
            p.UpdateValue(psb, "NickName", GoesBy);
            p.UpdateValue(psb, "OccupationOther", Occupation);
            p.UpdateValue(psb, "SchoolOther", School);
            p.UpdateValue(psb, "SuffixCode", Suffix);
            p.UpdateValue(psb, "EmployerOther", Employer);
            p.UpdateValue(psb, "TitleCode", Title.Value);
            p.UpdateValue(psb, "WeddingDate", WeddingDate.ToDate());
            p.UpdateValue(psb, "WorkPhone", Work.GetDigits());
            if (p.DeceasedDateChanged)
            {
                var ret = p.MemberProfileAutomation(DbUtil.Db);
                if (ret != "ok")
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(
                        new Exception(ret + " for PeopleId:" + p.PeopleId));
                }
            }


            p.LogChanges(DbUtil.Db, psb, Util.UserPeopleId.Value);
            p.Family.LogChanges(DbUtil.Db, fsb, p.PeopleId, Util.UserPeopleId.Value);

            DbUtil.Db.SubmitChanges();

            if (!HttpContext.Current.User.IsInRole("Access"))
            {
                if (psb.Length > 0 || fsb.Length > 0)
                {
                    DbUtil.Db.EmailRedacted(p.FromEmail, DbUtil.Db.GetNewPeopleManagers(),
                                            "Basic Person Info Changed on " + Util.Host,
                                            "{0} changed the following information for {1} ({2}):<br />\n<table>{3}{4}</table>"
                                            .Fmt(Util.UserName, FirstName + " " + LastName, PeopleId, psb.ToString(), fsb.ToString()));
                }
            }
        }
Exemple #5
0
        internal void AddPerson(int originid, int?entrypointid, int?campusid)
        {
            Family f;
            string na = "na";

            if (FamilyId > 0)
            {
                f = family;
            }
            else
            {
                f = new Family
                {
                    HomePhone      = HomePhone.GetDigits(),
                    AddressLineOne = Address.Disallow(na),
                    AddressLineTwo = Address2,
                    CityName       = City.Disallow(na),
                    StateCode      = State.Value.Disallow(na),
                    ZipCode        = Zip.Disallow(na),
                    CountryName    = Country.Value,
                }
            };

            if (GoesBy != null)
            {
                GoesBy = GoesBy.Trim();
            }
            var position = PositionInFamily.Child;

            if (!birthday.HasValue)
            {
                position = PositionInFamily.PrimaryAdult;
            }
            if (age >= 18)
            {
                if (f.People.Count(per =>
                                   per.PositionInFamilyId == PositionInFamily.PrimaryAdult)
                    < 2)
                {
                    position = PositionInFamily.PrimaryAdult;
                }
                else
                {
                    position = PositionInFamily.SecondaryAdult;
                }
            }

            _Person = CmsData.Person.Add(f, position,
                                         null, First.Trim(), GoesBy, Last.Trim(), dob, false, Gender.Value.ToInt(),
                                         originid, entrypointid);
            if (Title.HasValue())
            {
                person.TitleCode = Title;
            }
            person.EmailAddress    = Email.Disallow(na);
            person.MaritalStatusId = Marital.Value.ToInt();
            person.SuffixCode      = Suffix;
            person.MiddleName      = Middle;
            if (campusid == 0)
            {
                campusid = null;
            }
            person.CampusId = Util.PickFirst(campusid.ToString(), DbUtil.Db.Setting("DefaultCampusId", "")).ToInt2();
            if (person.CampusId == 0)
            {
                person.CampusId = null;
            }

            person.CellPhone = Phone.GetDigits();
            DbUtil.Db.SubmitChanges();
            DbUtil.Db.Refresh(RefreshMode.OverwriteCurrentValues, person);
            PeopleId = person.PeopleId;
        }
Exemple #6
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;
        }