Ejemplo n.º 1
0
        public ActionResult AddEditPerson(string data)
        {
            // Authenticate first
            if (!Auth())
            {
                return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS));
            }

            CheckInMessage       dataIn = CheckInMessage.createFromString(data);
            CheckInAddEditPerson aep    = JsonConvert.DeserializeObject <CheckInAddEditPerson>(dataIn.data);

            aep.clean();

            CheckInAddEditPersonResults results = new CheckInAddEditPersonResults();

            Family f;
            Person p;

            if (aep.edit)
            {
                p = CurrentDatabase.LoadPersonById(aep.id);

                f = CurrentDatabase.Families.First(fam => fam.FamilyId == p.FamilyId);

                f.HomePhone      = aep.homePhone;
                f.AddressLineOne = aep.address;
                f.AddressLineTwo = aep.address2;
                f.CityName       = aep.city;
                f.StateCode      = aep.state;
                f.ZipCode        = aep.zipcode;
                f.CountryName    = aep.country;
            }
            else
            {
                results.newPerson = true;

                p = new Person
                {
                    CreatedDate    = Util.Now,
                    CreatedBy      = CurrentDatabase.UserId,
                    MemberStatusId = MemberStatusCode.JustAdded,
                    AddressTypeId  = 10,
                    OriginId       = OriginCode.Visit,
                    EntryPoint     = getCheckInEntryPointID()
                };

                if (aep.campus > 0)
                {
                    p.CampusId = aep.campus;
                }

                p.Name = "";

                if (aep.familyID > 0)
                {
                    f = CurrentDatabase.Families.First(fam => fam.FamilyId == aep.familyID);
                }
                else
                {
                    results.newFamily = true;

                    f = new Family();
                    CurrentDatabase.Families.InsertOnSubmit(f);
                }

                f.HomePhone      = aep.homePhone;
                f.AddressLineOne = aep.address;
                f.AddressLineTwo = aep.address2;
                f.CityName       = aep.city;
                f.StateCode      = aep.state;
                f.ZipCode        = aep.zipcode;
                f.CountryName    = aep.country;

                f.People.Add(p);

                p.PositionInFamilyId = CurrentDatabase.ComputePositionInFamily(aep.getAge(), aep.maritalStatusID == MaritalStatusCode.Married, f.FamilyId) ?? PositionInFamily.PrimaryAdult;
            }

            p.FirstName = aep.firstName;
            p.LastName  = aep.lastName;
            p.NickName  = aep.goesBy;
            p.AltName   = aep.altName;

            if (dataIn.version >= CheckInMessage.API_V3)
            {
                p.SetRecReg().Fname = aep.father;
                p.SetRecReg().Mname = aep.mother;
            }

            // Check-In API Version 2 or greater adds the ability to clear the birthday
            if (dataIn.version >= CheckInMessage.API_V2)
            {
                if (aep.birthdaySet && aep.birthday != null)
                {
                    p.BirthDay   = aep.birthday.Value.Day;
                    p.BirthMonth = aep.birthday.Value.Month;
                    p.BirthYear  = aep.birthday.Value.Year;
                }
                else
                {
                    if (aep.birthdayClear)
                    {
                        p.BirthDay   = null;
                        p.BirthMonth = null;
                        p.BirthYear  = null;
                    }
                }
            }
            else
            {
                if (aep.birthday != null)
                {
                    p.BirthDay   = aep.birthday.Value.Day;
                    p.BirthMonth = aep.birthday.Value.Month;
                    p.BirthYear  = aep.birthday.Value.Year;
                }
            }

            p.GenderId        = aep.genderID;
            p.MaritalStatusId = aep.maritalStatusID;

            p.FixTitle();

            p.EmailAddress = aep.eMail;
            p.CellPhone    = aep.cellPhone;
            p.HomePhone    = aep.homePhone;

            p.SetRecReg().MedicalDescription = aep.allergies;

            p.SetRecReg().Emcontact = aep.emergencyName;
            p.SetRecReg().Emphone   = aep.emergencyPhone.Truncate(50);

            p.SetRecReg().ActiveInAnotherChurch = !string.IsNullOrEmpty(aep.church);
            p.OtherPreviousChurch = aep.church;

            CurrentDatabase.SubmitChanges();

            results.familyID = f.FamilyId;
            results.peopleID = p.PeopleId;
            results.position = p.PositionInFamilyId;

            CheckInMessage br = new CheckInMessage();

            br.setNoError();
            br.count = 1;
            br.data  = SerializeJSON(results, dataIn.version);

            return(br);
        }
Ejemplo n.º 2
0
        public ActionResult AddEditPerson(string data)
        {
            // Authenticate first
            if (!Auth())
            {
                return(BaseMessage.createErrorReturn("Authentication failed, please try again", BaseMessage.API_ERROR_INVALID_CREDENTIALS));
            }

            BaseMessage          dataIn = BaseMessage.createFromString(data);
            CheckInAddEditPerson aep    = JsonConvert.DeserializeObject <CheckInAddEditPerson>(dataIn.data);

            aep.clean();

            CheckInAddEditPersonResults results = new CheckInAddEditPersonResults();

            Family f;
            Person p;

            if (aep.edit)
            {
                p = DbUtil.Db.LoadPersonById(aep.id);

                f = DbUtil.Db.Families.First(fam => fam.FamilyId == p.FamilyId);

                f.HomePhone      = aep.homePhone;
                f.AddressLineOne = aep.address;
                f.AddressLineTwo = aep.address2;
                f.CityName       = aep.city;
                f.StateCode      = aep.state;
                f.ZipCode        = aep.zipcode;
                f.CountryName    = aep.country;
            }
            else
            {
                results.newPerson = true;

                p = new Person();

                p.CreatedDate = Util.Now;
                p.CreatedBy   = Util.UserId;

                p.MemberStatusId = MemberStatusCode.JustAdded;
                p.AddressTypeId  = 10;

                p.OriginId = OriginCode.Visit;

                p.Name = "";

                if (aep.familyID > 0)
                {
                    f = DbUtil.Db.Families.First(fam => fam.FamilyId == aep.familyID);
                }
                else
                {
                    results.newFamily = true;

                    f = new Family();
                    DbUtil.Db.Families.InsertOnSubmit(f);
                }

                f.HomePhone      = aep.homePhone;
                f.AddressLineOne = aep.address;
                f.AddressLineTwo = aep.address2;
                f.CityName       = aep.city;
                f.StateCode      = aep.state;
                f.ZipCode        = aep.zipcode;
                f.CountryName    = aep.country;

                f.People.Add(p);

                p.PositionInFamilyId = PositionInFamily.Child;

                if (aep.birthday != null && p.GetAge() >= 18)
                {
                    if (f.People.Count(per => per.PositionInFamilyId == PositionInFamily.PrimaryAdult) < 2)
                    {
                        p.PositionInFamilyId = PositionInFamily.PrimaryAdult;
                    }
                    else
                    {
                        p.PositionInFamilyId = PositionInFamily.SecondaryAdult;
                    }
                }
            }

            p.FirstName = aep.firstName;
            p.LastName  = aep.lastName;
            p.NickName  = aep.goesBy;

            if (aep.birthday != null)
            {
                p.BirthDay   = aep.birthday.Value.Day;
                p.BirthMonth = aep.birthday.Value.Month;
                p.BirthYear  = aep.birthday.Value.Year;
            }

            p.GenderId        = aep.genderID;
            p.MaritalStatusId = aep.maritalStatusID;

            p.FixTitle();

            p.EmailAddress = aep.eMail;
            p.CellPhone    = aep.cellPhone;
            p.HomePhone    = aep.homePhone;

            p.SetRecReg().MedicalDescription = aep.allergies;

            p.SetRecReg().Emcontact = aep.emergencyName;
            p.SetRecReg().Emphone   = aep.emergencyPhone.Truncate(50);

            p.SetRecReg().ActiveInAnotherChurch = aep.church != null && aep.church.Length > 0;
            p.OtherPreviousChurch = aep.church;

            DbUtil.Db.SubmitChanges();

            results.familyID = f.FamilyId;
            results.peopleID = p.PeopleId;
            results.position = p.PositionInFamilyId;

            BaseMessage br = new BaseMessage();

            br.setNoError();
            br.count = 1;
            br.data  = SerializeJSON(results, dataIn.version);

            return(br);
        }