public bool AddPhone(PersonInfoModel entryToAdd) { var sameNameEntries = from e in this.entries where e.Name.ToLowerInvariant() == entryToAdd.Name.ToLowerInvariant() select e; bool addedNewEntry; if (sameNameEntries.Count() == 0) { this.entries.Add(entryToAdd); addedNewEntry = true; } else if (sameNameEntries.Count() == 1) { PersonInfoModel oldEntry = sameNameEntries.First(); foreach (var phoneNumber in entryToAdd.Phones) { oldEntry.Phones.Add(phoneNumber); } addedNewEntry = false; } else { Console.WriteLine("Duplicated name in the phonebook found: " + entryToAdd.Name); return false; } return addedNewEntry; }
public bool AddPhone(PersonInfoModel model) { string name2 = model.Name.ToLowerInvariant(); PersonInfoModel entry; bool flag = !this.dict.TryGetValue(name2, out entry); if (flag) { entry = new PersonInfo(); entry.Name = model.Name; entry.Phones = new SortedSet<string>(); this.dict.Add(name2, entry); this.sorted.Add(entry); } foreach (var num in nums) { this.multidict.Add(num, entry); } entry.Phones.UnionWith(nums); return flag; }