private async void deleteExerciseButtonClick(object sender, EventArgs e) { List <WorkoutExerciseViewModel> models = new List <WorkoutExerciseViewModel>(); var answer = await DisplayAlert("Delete Workout Exercise", "Are you sure you want to delete " + WorkoutExerciseViewModel.exerciseName + " from this workout?", "Yes", "No"); if (answer) { //delete exercise from workout and reset list info WorkoutExerciseViewModel.deleteWorkoutExcerise(WorkoutExerciseViewModel); models = App.Database.getWorkoutExercises(cWorkout); editWorkoutExercises.ItemsSource = models; } }
private async void saveExerciseButtonClick(object sender, EventArgs e) { //WorkoutExerciseViewModel exerciseToAdd; string validateWorkoutExercise; int tempSets; int tempReps; if (setsEntryCell.Text == null) { tempSets = 0; } else { tempSets = int.Parse(setsEntryCell.Text); } if (repsEntryCell.Text == null) { tempReps = 0; } else { tempReps = int.Parse(repsEntryCell.Text); } if (exerciseSelected == "") { await DisplayAlert("Error Updating Workout Exercise", "Please select an exercise to add to this workout", "OK"); return; } if (exerciseType.SelectedItem == null) { await DisplayAlert("Error Updating Workout Exercise", "Please select exercise type to add exercise to this workout", "OK"); return; } if (exerciseType.SelectedItem.ToString() == "Rep-Based") { RepBasedExercise repBasedExercise = new RepBasedExercise(workoutExerciseViewModel.ID, cWorkout.ID, App.Database.getExerciseIDFromName(exerciseSelected), exerciseType.SelectedIndex + 1, "", tempSets, tempReps); validateWorkoutExercise = repBasedExercise.validateExercise(repBasedExercise); if (workoutExerciseViewModel.exerciseType == "Time-Based") { workoutExerciseViewModel.deleteWorkoutExcerise(workoutExerciseViewModel); repBasedExercise.ID = 0; } if (validateWorkoutExercise == null) { await App.Database.saveRepBasedExercise(repBasedExercise); } else { await DisplayAlert("Error Adding Exercise to Workout", "Detected the following errors when adding an exercise to this workout." + Environment.NewLine + validateWorkoutExercise, "OK"); } //WorkoutExerciseViewModel newExercise = new WorkoutExerciseViewModel(0, 0, App.Database.getExerciseIDFromName(exerciseSelected), exerciseSelected, exerciseType.SelectedItem.ToString(), int.Parse(setsEntryCell.Text),int.Parse(repsEntryCell.Text)); //exerciseToAdd = newExercise; } else { TimeBasedExercise timeBasedExercise = new TimeBasedExercise(workoutExerciseViewModel.ID, cWorkout.ID, App.Database.getExerciseIDFromName(exerciseSelected), exerciseType.SelectedIndex + 1, "", exerciseTimeType.SelectedIndex + 1, tempSets, tempReps); validateWorkoutExercise = timeBasedExercise.validateExercise(timeBasedExercise); if (workoutExerciseViewModel.exerciseType == "Rep-Based") { workoutExerciseViewModel.deleteWorkoutExcerise(workoutExerciseViewModel); timeBasedExercise.ID = 0; } if (validateWorkoutExercise == null) { App.Database.saveTimeBasedExercise(timeBasedExercise); } else { await DisplayAlert("Error Adding Exercise to Workout", "Detected the following errors when adding an exercise to this workout." + Environment.NewLine + validateWorkoutExercise, "OK"); } //WorkoutExerciseViewModel newExercise = new WorkoutExerciseViewModel(0, 0, App.Database.getExerciseIDFromName(selectedExercise.SelectedItem.ToString()), selectedExercise.SelectedItem.ToString(), exerciseType.SelectedItem.ToString(), int.Parse(setsEntryCell.Text),int.Parse(repsEntryCell.Text),exerciseTimeType.SelectedIndex + 1); //exerciseToAdd = newExercise; } //var answer = await DisplayAlert("Exercise Added", "Exercise Successfully Added to Workout." + Environment.NewLine + "Would you like to add another exericse?", "Yes", "No"); //if (answer) //{ // selectedExercise.SelectedItem = null; // exerciseType.SelectedIndex = -1; // setsEntryCell.Text = ""; // repsEntryCell.Text = ""; // exerciseTimeType.SelectedIndex = -1; // timeTypeStackLayout.IsVisible = false; // //reset exercise form. //} //else //{ // App.Current.MainPage = new MainPage(cTrainer, 2); //} //var workoutPage = new AddWorkout(cWorkout, workoutExercises, cTrainer); //await Navigation.PushAsync(workoutPage); //await Navigation.PopAsync(); await Navigation.PopModalAsync(); }