/// <summary> /// Deletes the exercise. /// </summary> private async void DeleteExercise() { ViewExerciseContentDialog.Hide(); var result = await DeleteExerciseContentDialog.ShowAsync(); var selectedExercise = (Exercise)ExercisesListView.SelectedItem; if (result != ContentDialogResult.Primary) { return; } if (selectedExercise == null) { return; } try { if (!await Tasks.Instance.DeleteTask(selectedExercise)) { await new MessageDialog("Failed to delete exercise", "Error").ShowAsync(); } } catch (Exception e) { await e.Display("Failed to delete exercise."); await e.Log(); } CourseExercises.Remove(selectedExercise); var selectedCourse = (Course)CoursesListView.SelectedItem; selectedCourse?.Exercises.Remove(selectedExercise); }
/// <summary> /// Edits the exercise. /// </summary> private async void EditExercise() { ViewExerciseContentDialog.Hide(); var selectedExercise = (Exercise)ExercisesListView.SelectedItem; EditExerciseContentDialog.DataContext = selectedExercise; var result = await EditExerciseContentDialog.ShowAsync(); if (result != ContentDialogResult.Primary) { return; } try { await Tasks.Instance.UpdateTask(selectedExercise); } catch (Exception ex) { await ex.Display("Failed to edit exercise."); await ex.Log(); } }