/// <summary> /// Returns true if the specified Contacts exists in the /// repository, or false if it is not. /// </summary> public bool ContainsContact(Contact contact) { if (contact == null) throw new ArgumentNullException("contact"); return _contacts.Contains(contact); }
public ContactViewModel(Contact contact, ContactRepository contactRepository) { if (contact == null) throw new ArgumentNullException("contact"); if (contactRepository == null) throw new ArgumentNullException("contactRepository"); _contact = contact; _contactRepository = contactRepository; }
public SearchContactsViewModel(Contact contact,ref ContactViewModel cvm, ContactRepository contactRepository) { base.DisplayName = Resources.SearchContactsViewModel_DisplayName; if (contact == null) throw new ArgumentNullException("contact"); if (contactRepository == null) throw new ArgumentNullException("contactRepository"); _contact = contact; _contactRepository = contactRepository; }
/// <summary> /// Places the specified Contacts into the repository. /// If the Contacts is already in the repository, an /// exception is not thrown. /// </summary> public void AddContact(Contact contact) { if (contact == null) throw new ArgumentNullException("contact"); if (!_contacts.Contains(contact)) { _contacts.Add(contact); if (this.ContactAdded != null) this.ContactAdded(this, new ContactAddedEventArgs(contact)); } }
/// <summary> /// Saves the Contacts to the repository. This method is invoked by the SeacrhCommand. /// </summary> public void Search() { if (!_contact.IsValidSearch) throw new InvalidOperationException(Resources.ContactViewModel_Exception_CannotSearch); _isFound = false; OnPropertyChanged("IsFound"); string searchLastName= string.Empty; if (!string.IsNullOrEmpty(this.LastName)) { searchLastName = this.LastName.ToLower(); List<ContactViewModel> all = (from cont in _contactRepository.GetContacts() select new ContactViewModel(cont, _contactRepository)).ToList(); this.AllContacts = new ObservableCollection<ContactViewModel>(all); Contact contact = new Contact(); foreach (ContactViewModel cvmTemp in AllContacts) { if (cvmTemp.LastName.ToLower().Contains(searchLastName)) { displaySearch.Add(cvmTemp); contact.FirstName = cvmTemp.FirstName; contact.LastName = cvmTemp.LastName; contact.Email = cvmTemp.Email; contact.PhoneNumber = cvmTemp.PhoneNumber; _lstSearchedContacts.Add(contact); _isFound = true; } } } base.OnPropertyChanged("isFound"); base.OnPropertyChanged("DisplayName"); }
public ContactAddedEventArgs(Contact newContact) { this.NewContact = newContact; }
/// <summary> /// Write the contacts to a different xml file present in debug folder. /// </summary> /// <param name="newContacts"></param> public void WriteToXML(Contact newContacts) { XDocument doc = XDocument.Load(path); XElement school = doc.Element("contacts"); school.Add(new XElement("contact", new XAttribute("lastName", newContacts.LastName), new XAttribute("firstName", newContacts.FirstName), new XAttribute("email", newContacts.Email), new XAttribute("phoneNumber", newContacts.PhoneNumber))); doc.Save(path); }