/// <summary> /// Adds frequency data for a name. /// </summary> /// <param name="name">The name to add data to.</param> /// <param name="sex">The sex for which this data is being added.</param> /// <param name="year">The year in which the name was used.</param> /// <param name="occs">The number of times the name was used.</param> private void AddFrequency(Name name, Sex sex, Int32 year, Int64 occs) { // try to get the usage version of this name NameUsage usage = name.UsageFor(this.Culture, sex); // create it if it does not exist if (usage == null) { usage = new NameUsage(this.Culture, sex); usage.NameID = name.ID; usage.Name = name; name.Usage.Add(usage); this.context.Usage.Add(usage); this.Commit(); } // try to get an existing frequency entry DateTime periodStart = new DateTime(year, 1, 1); DateTime periodEnd = new DateTime(year, 12, 31); NameFrequency frequency = usage.Frequency.SingleOrDefault(x => x.PeriodStart.Equals(periodStart) && x.PeriodEnd.Equals(periodEnd)); // create it if it doesn't exist if (frequency == null) { frequency = new NameFrequency(periodStart, periodEnd); frequency.NameUsedID = usage.ID; frequency.NameUsed = usage; frequency.Type = FrequencyType.Birth; frequency.Occurrences = occs; usage.Frequency.Add(frequency); this.context.Frequency.Add(frequency); this.Commit(); } }
public static NameFrequencyModel ToModel(this NameFrequency person) { return(Mapper.DynamicMap <NameFrequency, NameFrequencyModel>(person)); }