private async void MenuItemRename_Click(object sender, RoutedEventArgs e) { if (this.listBox.SelectedIndex == -1) { return; } var item = listBox.Items[listBox.SelectedIndex]; if (SetAlbumsDetails()) { try { String msg = await AlbumsProcessor.updateAlbum((item as AlbumModel)._id, this.AlbumName, this.CreationDate, this.UserId); MessageBox.Show(msg); LoadAlbums(this.UserId); } catch { MessageBox.Show("Error while update user"); } } }
public async void addAlbum() { if (SetAlbumsDetails()) { try { String msg = await AlbumsProcessor.addAlbum(this.AlbumName, this.CreationDate, this.UserId); MessageBox.Show(msg); LoadAlbums(this.UserId); } catch { MessageBox.Show("Error while adding user"); } } }
private async void MenuItemDelete_Click(object sender, RoutedEventArgs e) { if (this.listBox.SelectedIndex == -1) { return; } var item = listBox.Items[listBox.SelectedIndex]; try { String msg = await AlbumsProcessor.deleteAlbum((item as AlbumModel)._id); MessageBox.Show(msg); LoadAlbums(this.UserId); } catch { MessageBox.Show("Error while deleting user"); } }
public async void LoadAlbums(String userId) { mainGrid.Children.Clear(); var scroll = new ScrollViewer(); mainGrid.Children.Add(scroll); this.listBox = new ListBox(); scroll.Content = listBox; listBox.DisplayMemberPath = "Text"; try { var albums = await AlbumsProcessor.GetAllAlbumsOfUser(userId); foreach (var album in albums) { listBox.Items.Add(album); } } catch { MessageBox.Show("Error while loading users"); } ContextMenu contextMenu = new ContextMenu(); MenuItem item = new MenuItem(); item.Header = "Rename"; item.Click += MenuItemRename_Click; contextMenu.Items.Add(item); item = new MenuItem(); item.Header = "Delete"; item.Click += MenuItemDelete_Click; contextMenu.Items.Add(item); scroll.ContextMenu = contextMenu; listBox.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnMouseLeftButtonDown), true); }