public GadgetViewModel() { initalLoadGadgets(); newGadgetCom = new RelayCommand <Gadget>((x) => funcNewGadget(), (x) => true); delGadgetCom = new RelayCommand <Gadget>((x) => funcDelGadget(), (x) => true); client.NotificationReceived += (o, e) => { Console.WriteLine("WebSocket::Notification: " + e.Notification.Target + " > " + e.Notification.Type); // demonstrate how these updates could be further used if (e.Notification.Target == typeof(Gadget).Name.ToLower()) { // deserialize the json representation of the data object to an object of type Gadget var gadget = e.Notification.DataAs <Gadget>(); switch (e.Notification.Type) { case WebSocketClientNotificationTypeEnum.Add: Gadgets.Add(gadget); break; case WebSocketClientNotificationTypeEnum.Delete: Gadgets.Remove(gadget); break; } } }; var bgTask = client.ListenAsync(); }
public void RemoveGadget() { try { if (SelectedGadget != null) { MessageBoxResult dialogResult = MessageBox.Show($"Sind Sie sicher, dass Sie{Environment.NewLine}{Environment.NewLine}{SelectedGadget.FullDescription()}{Environment.NewLine}{Environment.NewLine}löschen möchten?", "Löschen bestätigen", MessageBoxButton.YesNo); if (dialogResult == MessageBoxResult.Yes) { if (libraryAdminService.DeleteGadget(SelectedGadget)) { Gadgets.Remove(SelectedGadget); } else { MessageBox.Show("Fehler beim Löschen des Gadgets. Bitte versuchen Sie es nochmals.", "Löschen fehlgeschlagen", MessageBoxButton.OK); } } } } catch (InvalidCastException exception) { MessageBox.Show("Fehler beim Löschen des Gadgets. Bitte versuchen Sie es nochmals.", "Löschen fehlgeschlagen", MessageBoxButton.OK); Debug.Print(exception.ToString()); } }
private void Delete() { if (MessageBox.Show(Properties.Resources.DELETE_CONFIRMATION_TEXT, Properties.Resources.DELETE_CONFIRMATION_TITLE, MessageBoxButton.YesNo) == MessageBoxResult.Yes) { libraryAdminService.DeleteGadget(SelectedGadget); Gadgets.Remove(SelectedGadget); SelectedGadget = Gadgets.ElementAt(0); } }
public static void Delete(Gadget gadget) { MessageBoxResult messageBoxResult = MessageBox.Show(String.Format("Are you sure you want delete this gadget:\n{0} ({1})", gadget.Name, gadget.Manufacturer), "Delete Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (messageBoxResult == MessageBoxResult.Yes) { if (Service.DeleteGadget(gadget)) { Gadgets.Remove(gadget); } else { messageBoxResult = MessageBox.Show("Could not delete selected gadget.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }