/// <inheritdoc /> public AddressBookEntry RemoveAddress(string label) { AddressBookEntry item = this.addressBook.Addresses.SingleOrDefault(i => i.Label == label); if (item == null) { return(null); } this.addressBook.Addresses.Remove(item); this.fileStorage.SaveToFile(this.addressBook, AddressBookFileName); return(item); }
/// <inheritdoc /> public AddressBookEntry AddNewAddress(string label, string address) { if (this.addressBook.Addresses.Any(i => i.Label == label || i.Address == address)) { throw new AddressBookException($"An entry with label '{label}' or address '{address}' already exist in the address book."); } AddressBookEntry newEntry = new AddressBookEntry { Label = label, Address = address }; this.addressBook.Addresses.Add(newEntry); this.fileStorage.SaveToFile(this.addressBook, AddressBookFileName); return(newEntry); }