public void InsertOrUpdate(MaritialStatus maritialstatus)
 {
     if (maritialstatus.Id == default(int))
     {
         // New entity
         context.MaritialStatus.Add(maritialstatus);
     }
     else
     {
         // Existing entity
         context.Entry(maritialstatus).State = EntityState.Modified;
     }
 }
示例#2
0
        /// <summary>
        /// Will create a current and, possiably, past spouses for this instance.
        /// Calc' will be based on DOB and <see cref="IPerson.MyGender"/>.
        /// </summary>
        /// <param name="myMaritialStatus"></param>
        protected internal void ResolveSpouse(MaritialStatus myMaritialStatus)
        {
            if (myMaritialStatus == MaritialStatus.Single || myMaritialStatus == MaritialStatus.Unknown)
                return;

            var dt = DateTime.Now;

            ThrowOnBirthDateNull(this);

            var avgAgeMarriage = MyGender == Gender.Female
                ? NAmerUtil.Equations.FemaleAge2FirstMarriage.SolveForY(_birthCert.DateOfBirth.ToDouble())
                : NAmerUtil.Equations.MaleAge2FirstMarriage.SolveForY(_birthCert.DateOfBirth.ToDouble());
            var currentAge = Person.CalcAge(_birthCert.DateOfBirth, dt);

            //all other MaritialStatus imply at least one marriage in past
            var yearsMarried = currentAge - Convert.ToInt32(Math.Round(avgAgeMarriage));

            var marriedOn = Etx.Date(-1*yearsMarried, dt).Date.AddHours(12);

            var spouse = (NorthAmerican)NAmerUtil.SolveForSpouse(_birthCert.DateOfBirth, MyGender);

            //set death date if widowed
            if (myMaritialStatus == MaritialStatus.Widowed)
            {
                var d = Convert.ToInt32(Math.Round(GetAgeAt(null) * 0.15));
                spouse.DeathDate = Etx.Date(Etx.IntNumber(1, d), null);
            }

            if (myMaritialStatus != MaritialStatus.Divorced && myMaritialStatus != MaritialStatus.Remarried &&
                myMaritialStatus != MaritialStatus.Separated)
            {
                //add internal date-range for resolution of children
                AddNewSpouseToList(spouse, marriedOn);
            }
            else
            {
                //take date of marriage and add avg length of marriage
                var separatedDate = Etx.Date(NAmerUtil.AVG_LENGTH_OF_MARRIAGE, marriedOn);

                //reset date-range with separated date
                AddNewSpouseToList(spouse, marriedOn, separatedDate);

                //leave when no second spouse applicable
                if (myMaritialStatus != MaritialStatus.Remarried)
                    return;

                var ageSpread = 6;
                if (MyGender == Gender.Male)
                    ageSpread = 10;

                //get a second spouse
                var secondSpouse = (NorthAmerican)NAmerUtil.SolveForSpouse(_birthCert.DateOfBirth, MyGender, ageSpread);

                //random second marriage date
                var remarriedOn = Etx.Date(Convert.ToInt32(Math.Round(NAmerUtil.YEARS_BEFORE_NEXT_MARRIAGE)),
                    separatedDate);

                //add second date-range for resolution of children
                AddNewSpouseToList(secondSpouse, remarriedOn);
            }
        }
示例#3
0
        /// <summary>
        /// Gets the sum of the factors based on the criteria.
        /// </summary>
        /// <param name="tbl"></param>
        /// <param name="edu"></param>
        /// <param name="race"></param>
        /// <param name="region"></param>
        /// <param name="age"></param>
        /// <param name="gender"></param>
        /// <param name="maritialStatus"></param>
        /// <returns></returns>
        internal static double GetFactor(FactorTables tbl, OccidentalEdu edu, NorthAmericanRace race,
            AmericanRegion region, int age, Gender gender, MaritialStatus maritialStatus)
        {
            var xmlDoc = tbl == FactorTables.CreditCardDebt || tbl == FactorTables.HomeDebt ||
                         tbl == FactorTables.VehicleDebt
                ? TreeData.UsPersonalDebt
                : TreeData.UsPersonalWealth;
            var tblName = Enum.GetName(typeof(FactorTables), tbl);
            var eduName = GetXmlEduName(edu);
            var raceName = Enum.GetName(typeof(NorthAmericanRace), race);
            var regionName = Enum.GetName(typeof(AmericanRegion), region);
            var genderName = Enum.GetName(typeof(Gender), gender);

            var tblXPath = $"//table[@name='{tblName}']";

            var sum = 0.0D;
            var hash = new Dictionary<string, string>
            {
                {"Edu", eduName},
                {"Race", raceName},
                {"Region", regionName},
            };

            foreach (var factor in hash.Keys)
            {
                var xmlElem = xmlDoc.SelectSingleNode($"{tblXPath}/factor[@name='{factor}']/add[@name='{hash[factor]}']") as XmlElement;
                var factorVal = xmlElem?.Attributes["value"]?.Value;
                if (string.IsNullOrWhiteSpace(factorVal))
                    continue;
                double dblOut;
                if (double.TryParse(factorVal, out dblOut))
                    sum += dblOut;
            }

            var ageNode = maritialStatus == MaritialStatus.Remarried || maritialStatus == MaritialStatus.Remarried
                ? xmlDoc.SelectSingleNode($"{tblXPath}/factor[@name='Age']/factor[@name='Married']")
                : xmlDoc.SelectSingleNode($"{tblXPath}/factor[@name='Age']/factor[@name='{genderName}']");
            if (ageNode == null)
                return sum;
            foreach (var anode in ageNode.ChildNodes)
            {
                var ageElem = anode as XmlElement;
                if (ageElem == null)
                    continue;
                var minAge = ageElem.Attributes["min"]?.Value;
                var maxAge = ageElem.Attributes["max"]?.Value;
                if (string.IsNullOrWhiteSpace(minAge) || string.IsNullOrWhiteSpace(maxAge))
                    continue;
                int min, max;
                if (!int.TryParse(minAge, out min) || !int.TryParse(maxAge, out max))
                    continue;
                var isInRange = age >= min && age <= max;
                if (!isInRange || string.IsNullOrWhiteSpace(ageElem.Attributes["value"]?.Value))
                    continue;
                var factorVal = ageElem.Attributes["value"].Value;
                double dblOut;
                if (double.TryParse(factorVal, out dblOut))
                    sum += dblOut;
            }
            return sum;
        }
示例#4
0
        private void ProcessUpdateMaritialStatus(MaritialStatus existingMaritialStatus, MaritialStatus newMaritialStatus, long existingMaritialWith, long newMaritialWith)
        {
            long relationId = newMaritialWith;

            User relation = null;

            if (relationId > 0)
            {
                core.PrimitiveCache.LoadUserProfile(relationId);
                relation = core.PrimitiveCache[relationId];
            }

            if (relation != null)
            {
                if (LoggedInMember.Id != relation.Id)
                {
                    LoggedInMember.Profile.MaritialWithId = relation.Id;
                }
                else
                {
                    LoggedInMember.Profile.MaritialWithId = 0;
                }
            }
            else
            {
                LoggedInMember.Profile.MaritialWithId = 0;
            }

            switch (newMaritialStatus)
            {
                case MaritialStatus.MonogomousRelationship:
                case MaritialStatus.OpenRelationship:
                case MaritialStatus.Engaged:
                case MaritialStatus.Married:
                    if (relation != null && relation.Id != existingMaritialWith)
                    {
                        ApplicationEntry ae = core.GetApplication("Profile");

                        ae.SendNotification(core, LoggedInMember, relation, LoggedInMember.ItemKey, LoggedInMember.ItemKey, "_WANTS_TO_CONFIRM_RELATIONSHIP", LoggedInMember.Uri, "relationship");

                        if (existingMaritialWith > 0)
                        {
                            core.LoadUserProfile(existingMaritialWith);
                            User oldRelation = core.PrimitiveCache[existingMaritialWith];

                            oldRelation.Profile.MaritialWithId = 0;
                            oldRelation.Profile.MaritialWithConfirmed = false;
                            oldRelation.Profile.MaritialStatusRaw = MaritialStatus.Undefined;

                            oldRelation.Profile.Update();
                        }
                    }
                    else
                    {
                        LoggedInMember.Profile.MaritialWithId = 0;
                        LoggedInMember.Profile.MaritialWithConfirmed = false;

                        if (existingMaritialWith > 0)
                        {
                            core.LoadUserProfile(existingMaritialWith);
                            User oldRelation = core.PrimitiveCache[existingMaritialWith];

                            oldRelation.Profile.MaritialWithId = 0;
                            oldRelation.Profile.MaritialWithConfirmed = false;
                            oldRelation.Profile.MaritialStatusRaw = MaritialStatus.Undefined;

                            oldRelation.Profile.Update();
                        }
                    }
                    break;
                default:
                    switch (existingMaritialStatus)
                    {
                        case MaritialStatus.MonogomousRelationship:
                        case MaritialStatus.OpenRelationship:
                        case MaritialStatus.Engaged:
                        case MaritialStatus.Married:
                            if (existingMaritialWith > 0)
                            {
                                core.LoadUserProfile(existingMaritialWith);
                                relation = core.PrimitiveCache[existingMaritialWith];

                                LoggedInMember.Profile.MaritialWithId = 0;
                                LoggedInMember.Profile.MaritialWithConfirmed = false;

                                relation.Profile.MaritialWithId = 0;
                                relation.Profile.MaritialWithConfirmed = false;
                                relation.Profile.MaritialStatusRaw = MaritialStatus.Undefined;

                                relation.Profile.Update();
                            }
                            break;
                        default:
                            // Ignore if empty or null
                            break;
                    }
                    break;
            }
        }