public void DeleteArticle(object input = null) { // 1. Ask user if they are sure if (_dialogService.OpenDialog(new DialogYesNoViewModel( "Delete following record?\n" + SelectedArticle.Title, "Delete article", DialogType.Warning ))) { // 2. Delete article record from database new ArticleRepo().DeleteArticle(SelectedArticle); // 3. Delete physical .pdf file try { File.Delete(Path.Combine(Environment.CurrentDirectory, "Files\\") + SelectedArticle.FileName + ".pdf"); } catch { _dialogService.OpenDialog( new DialogOkViewModel("The file is missing, validate your database.", "Error", DialogType.Error)); } // 4. Refresh the data grid LoadArticlesCommand.Execute(null); } }
public void DeleteArticle(object input = null) { try { // 1. Ask user if they are sure if (_dialogService.OpenDialog( new DialogYesNoViewModel("Delete following record?\n" + SelectedArticle.Title, "Warning", DialogType.Question) )) { // 2. Delete article record from database new ArticleRepo().DeleteArticle(SelectedArticle); // 2.2 Track article delete new Tracker(User).TrackDelete("Article", SelectedArticle.Title); // 3. Delete physical .pdf file try { File.Delete(Path.Combine(Environment.CurrentDirectory, "Files\\") + SelectedArticle.FileName + ".pdf"); } catch { _dialogService.OpenDialog( new DialogOkViewModel("The file is missing, validate your database.", "Error", DialogType.Error)); } // 4. Refresh the data grid LoadArticlesCommand.Execute(null); } } catch (Exception e) { new BugTracker().Track("Data View", "Delete Article", e.Message, e.StackTrace); _dialogService.OpenDialog(new DialogOkViewModel("Something went wrong.", "Error", DialogType.Error)); } }