private void SelectSocialTypesCommandHandler(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { try { if ((SocialTypesList.SelectedItems.Count > 0)) { var cur = customersViewSource.View.CurrentItem as customer; socialtype transsocialtype = (socialtype)SocialTypesList.SelectedItems[0]; foreach (customersocialtype var in cur.customersocialtypes) { if ((var.IdCustomer == cur.IdCustomer) && (var.IdSocialType == transsocialtype.IdSocialType)) { MessageBox.Show("Підопічний уже має такий соціальний тип!", "Помилка"); return; } } cur.customersocialtypes.Add(new customersocialtype() { customer = cur, socialtype = transsocialtype }); context.SaveChanges(); customercustomersocialtypesViewSource.View.Refresh(); } } catch (Exception ex) { MessageBox.Show("Щойно відбувся оброблений виняток: " + ex.Message, "Помилка", MessageBoxButton.OK); } }
private void UpdateCommandHandler(object sender, RoutedEventArgs e) { if (MessageBox.Show("Ви точно хочете зберегти запис?", "Підтвердження", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { if (newSocialTypeGrid.IsVisible) { socialtype newSocialTypes = new socialtype { Title = add_titleTextBox.Text.Trim(), Description = add_descriptionTextBox.Text.Trim() }; context.socialtypes.Local.Insert(0, newSocialTypes); socialTypeViewSource.View.Refresh(); socialTypeViewSource.View.MoveCurrentTo(newSocialTypes); newSocialTypeGrid.Visibility = Visibility.Collapsed; SocialTypeServiceGrid.Visibility = Visibility.Visible; existingSocialTypeGrid.Visibility = Visibility.Visible; } context.SaveChanges(); socialTypeViewSource.View.Refresh(); } }