public async void addImage() { OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = "c:\\"; dlg.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png"; dlg.RestoreDirectory = true; if (dlg.ShowDialog() == true) { this.ImagePath = dlg.FileName; this.ImageName = System.IO.Path.GetFileName(this.ImagePath); this.CreationDate = DateTime.Now.ToString("d/M/yyyy - HH:mm:ss"); try { String msg = await ImagesProcessor.addImage(this.ImageName, this.CreationDate, this.ImagePath, this.AlbumId); MessageBox.Show(msg); LoadImages(this.AlbumId); } catch { MessageBox.Show("Error while adding user"); } } }
private async void MenuItemRename_Click(object sender, RoutedEventArgs e) { if (this.listBox.SelectedIndex == -1) { return; } var item = listBox.Items[listBox.SelectedIndex]; if (SetImagesDetails()) { try { String msg = await ImagesProcessor.updateImage((item as ImageModel)._id, this.ImageName, this.CreationDate, (item as ImageModel).Location, this.AlbumId); MessageBox.Show(msg); LoadImages(this.AlbumId); } catch { MessageBox.Show("Error while update image"); } } }
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 ImagesProcessor.deleteImage((item as ImageModel)._id); MessageBox.Show(msg); LoadImages(this.AlbumId); } catch { MessageBox.Show("Error while deleting image"); } }
public async void LoadImages(String albumId) { mainGrid.Children.Clear(); var scroll = new ScrollViewer(); mainGrid.Children.Add(scroll); this.listBox = new ListBox(); scroll.Content = listBox; listBox.DisplayMemberPath = "Text"; try { var Images = await ImagesProcessor.GetAllImagesOfAlbum(albumId); foreach (var Image in Images) { listBox.Items.Add(Image); } } 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); }