private void EditContact_Executed(object sender, ExecutedRoutedEventArgs e) { ContactWindow contactWindow = new ContactWindow(Dealer.Contacts.First(x => x.Id == (long)(Contacts.SelectedItem as TextBlock).Tag).Clone()); if ((bool)contactWindow.ShowDialog(this)) { Dealer.Contacts[Dealer.Contacts.FindIndex(x => x.Id == contactWindow.Contact.Id)] = contactWindow.Contact; UpdateContacts(); Contacts.SelectItem(Contacts.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == contactWindow.Contact.Id)); } }
private void AddContact_Click(object sender, RoutedEventArgs e) { ContactWindow contactWindow = new ContactWindow(); if ((bool)contactWindow.ShowDialog(this)) { contactWindow.Contact.Id = Dealer.Contacts.Count != 0 ? Dealer.Contacts.Max(x => x.Id) + 1 : 1; Dealer.Contacts.Add(contactWindow.Contact); UpdateContacts(); Contacts.SelectItem(Contacts.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == contactWindow.Contact.Id)); } }
private void Accept_CanExecute(object sender, CanExecuteRoutedEventArgs e) { if (IsLoaded) { ContactWindow contactWindow = Owner as ContactWindow; switch (contactWindow.CommunicationMean.SelectedIndex) { case 0: e.CanExecute = TextBox.IsMaskFull && !(Value != TextBox.Text && contactWindow.Contact.Phones.Any(x => x.Value == TextBox.Text)); break; case 1: e.CanExecute = TextBox.IsMaskFull && !(Value != TextBox.Text && contactWindow.Contact.Faxes.Any(x => x.Value == TextBox.Text)); break; case 2: string pattern = @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z"; e.CanExecute = Regex.IsMatch(TextBox.Text, pattern, RegexOptions.IgnoreCase) && !(Value.ToUpper() != TextBox.Text.ToUpper() && contactWindow.Contact.Emails.Any(x => x.Value.ToUpper() == TextBox.Text.ToUpper())); break; } } }