private static void CheckIfDesireViolatesCategory([NotNull] PersonDesireDto desire, [NotNull] CalcPersonDesires calcDesires, [NotNull] CalcPerson person, [NotNull] string householdName) { string desirecategory = desire.DesireCategory; if (string.IsNullOrWhiteSpace(desirecategory)) { return; } if (calcDesires.Desires.ContainsKey(desire.DesireID)) { return; } var existingDesireCategories = calcDesires.Desires.Values.Select(x => x.DesireCategory).Distinct().ToList(); if (existingDesireCategories.Contains(desirecategory)) { var existingdesires = calcDesires.Desires.Values.Where(x => x.DesireCategory == desirecategory).ToList(); var source = existingdesires[0]; throw new DataIntegrityException("Trying to add two desires from the desire category " + Environment.NewLine + desirecategory + " to the person " + person.Name + " in the household " + householdName + ". This is not permitted. " + "Please fix. The first desire was " + Environment.NewLine + source.Name + " from " + source.SourceTrait + " and the second desire was " + Environment.NewLine + desire.Name + " from " + desire.SourceTrait + Environment.NewLine); } }
private void AddDesireToPerson([NotNull] PersonDesireDto desire, [NotNull] CalcPerson calcPerson, [NotNull] Dictionary <string, SharedDesireValue> sharedDesireValues, [NotNull] string householdName) { var sdv = GetSharedDesireValue(desire, sharedDesireValues); var cd1 = new CalcDesire(desire.Name, desire.DesireID, desire.Threshold, desire.DecayTime, 1, desire.Weight, _calcRepo.CalcParameters.TimeStepsPerHour, desire.CriticalThreshold, sdv, desire.SourceTrait, desire.DesireCategory); if (desire.HealthStatus == HealthStatus.Healthy || desire.HealthStatus == HealthStatus.HealthyOrSick) { CheckIfDesireViolatesCategory(desire, calcPerson.PersonDesires, calcPerson, householdName); calcPerson.PersonDesires.AddDesires(cd1); } if (desire.HealthStatus == HealthStatus.Sick || desire.HealthStatus == HealthStatus.HealthyOrSick) { CheckIfDesireViolatesCategory(desire, calcPerson.SicknessDesires, calcPerson, householdName); calcPerson.SicknessDesires.AddDesires(cd1); } }
private static SharedDesireValue GetSharedDesireValue([NotNull] PersonDesireDto desire, [NotNull] Dictionary <string, SharedDesireValue> sharedDesireValues) { if (desire.IsSharedDesire) { /* * if (sharedDesireValues == null) * { * throw new LPGException("Shared desire values was null"); * }*/ if (sharedDesireValues.ContainsKey(desire.Name)) { return(sharedDesireValues[desire.Name]); } var sdv = new SharedDesireValue(1, null); sharedDesireValues.Add(desire.Name, sdv); return(sdv); } return(null); }