/// <summary> /// Action method for adding new media files to an album. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void import_fileDialogue_Click(object sender, RoutedEventArgs e) { //TODO: add method to prevent Duplication in code (DRY) //Check if an album is already open or not. if (openAlbumIndex != -1 && openAlbumIndex < albumManager.Count()) { Album album = albumManager.GetAlbumAtIndex(openAlbumIndex); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image files (*.JPG;*.PNG)|*.JPG;*.PNG|" + "Video files (*.WMV;*.MP4)|*.WMV;*.MP4|" + "All supported files|*.JPG;*.PNG;*.WMV;*.MP4"; openFileDialog.FilterIndex = 3; //Default filter is: All supported files. openFileDialog.Multiselect = true; //Users can select multiple media files to import at once. if (openFileDialog.ShowDialog() == true) { foreach (var filePath in openFileDialog.FileNames) { string extension = Path.GetExtension(filePath); string fileName = Path.GetFileName(filePath); if (album.MediaFiles.Any(o => o.FilePath == filePath)) { MessageBoxResult result = MessageBox.Show($"{fileName} already exists in this album, would you like to add it anyway?", "File already exists", MessageBoxButton.YesNo); MediaFile file; switch (result) { case MessageBoxResult.Yes: switch (extension) { case ".jpg": case ".png": file = new ImageFile(fileName, "", filePath); album.MediaFiles.Add(file); break; case ".wmv": case ".mp4": file = new VideoFile(fileName, "", filePath); album.MediaFiles.Add(file); break; } break; case MessageBoxResult.No: //Do Nothing break; } } else { try { MediaFile file; switch (extension) { case ".jpg": case ".png": //album.MediaFiles.Add(new ImageFile(fileName, "", filePath)); file = new ImageFile(fileName, "", filePath); album.MediaFiles.Add(file); break; case ".wmv": case ".mp4": //album.MediaFiles.Add(new VideoFile(fileName, "", filePath)); file = new VideoFile(fileName, "", filePath); album.MediaFiles.Add(file); break; } } catch { MessageBox.Show("Error importing file(s) "); } } } } } }