private async void saveButtonClick(object sender, EventArgs e) { //validate date is not less than today and no other workout scheduled cClientWorkouts.scheduledDate = scheduledDate.Date; if (cClientWorkouts.scheduledDate < DateTime.Today) { await DisplayAlert("Error Saving Workout", "Cannot change a workout date to before current date.", "OK"); return; } if (App.Database.verifyClientWorkoutDates(cClientWorkouts) > 0) { await DisplayAlert("Error Saving Workout", "Client already has a workout scheduled for this day." + Environment.NewLine + "Please select a different date or delete the current workout on this day.", "OK"); return; } ClientWorkouts clientWorkouts = new ClientWorkouts(cClientWorkouts.ID, cClientWorkouts.clientID, cClientWorkouts.workoutID, cClientWorkouts.scheduledDate, cClientWorkouts.completedDate); await App.Database.saveClientWorkout(clientWorkouts); await Navigation.PopAsync(); }
private void PendingWorkouts_ItemSelected(object sender, SelectedItemChangedEventArgs e) { ClientWorkoutsViewModel clientWorkout = e.SelectedItem as ClientWorkoutsViewModel; //ClientWorkouts workouts = e.SelectedItem as ClientWorkoutsViewModel; ClientWorkouts workouts = new ClientWorkouts(clientWorkout.ID, clientWorkout.clientID, clientWorkout.workoutID, clientWorkout.scheduledDate, clientWorkout.completedDate); selectedWorkout = clientWorkout; //selectedWorkout = workouts; }
public ClientWorkoutsViewModel(ClientWorkouts clientWorkouts) { Workout workout = App.Database.loadWorkoutFromID(clientWorkouts.workoutID); this.ID = clientWorkouts.ID; this.clientID = clientWorkouts.clientID; this.workoutID = clientWorkouts.workoutID; this.scheduledDate = clientWorkouts.scheduledDate; this.completedDate = clientWorkouts.completedDate; this.name = workout.name; this.description = workout.description; }
private async void addWorkoutButtonClick(object sender, EventArgs e) { if (scheduledDate.Date < DateTime.Today) { await DisplayAlert("Error Saving Workout", "Cannot save a workout date to before current date.", "OK"); return; } if (selectedWorkout == null) { await DisplayAlert("Error Saving Workout", "Please select a workout to add to this client", "OK"); return; } ClientWorkouts clientWorkouts = new ClientWorkouts(0, pkClientID, selectedWorkout.ID, scheduledDate.Date); ClientWorkoutsViewModel viewModel = new ClientWorkoutsViewModel(clientWorkouts.ID, clientWorkouts.clientID, clientWorkouts.workoutID, clientWorkouts.scheduledDate, clientWorkouts.completedDate, "", ""); if (App.Database.verifyClientWorkoutDates(viewModel) > 0) { await DisplayAlert("Error Saving Workout", "Client already has a workout scheduled for the selected day." + Environment.NewLine + "Please select a different date to add this workout plan.", "OK"); return; } var answer = await DisplayAlert("Add Workout", "Are you sure you want to add the " + selectedWorkout.name + " workout to this client?", "Yes", "No"); if (!answer) { return; } else { clientWorkouts.scheduledDate = scheduledDate.Date; await App.Database.saveClientWorkout(clientWorkouts); await Navigation.PopAsync(); } }
private async void deleteWorkoutButtonClick(object sender, EventArgs e) { if (selectedWorkout == null) { await DisplayAlert("No Workout Selected", "Please select a workout to complete this action.", "OK"); return; } ClientWorkouts clientWorkouts = new ClientWorkouts(selectedWorkout.ID, selectedWorkout.clientID, selectedWorkout.workoutID, selectedWorkout.scheduledDate, selectedWorkout.completedDate); var answer = await DisplayAlert("Delete Workout", "Are you sure you want to delete this workout?", "Yes", "No"); if (answer) { await App.Database.DeleteClientWorkout(clientWorkouts); } pendingWorkouts.ItemsSource = App.Database.getNewPendingClientWorkouts(cClient); }
private async void addWorkoutPlanButtonClick(object sender, EventArgs e) { if (scheduledDate.Date < DateTime.Today) { await DisplayAlert("Error Saving Workout", "Cannot change a workout date to before current date.", "OK"); return; } if (selectedPlan == null) { await DisplayAlert("Error Saving Workout Plan", "Please select a workout plan to add to this client.", "OK"); return; } ClientWorkouts clientWorkouts = new ClientWorkouts(0, pkClientID, 1, scheduledDate.Date); ClientWorkoutsViewModel viewModel = new ClientWorkoutsViewModel(clientWorkouts.ID, clientWorkouts.clientID, clientWorkouts.workoutID, clientWorkouts.scheduledDate, clientWorkouts.completedDate, "", ""); if (App.Database.verifyClientWorkoutDates(viewModel) > 0) { await DisplayAlert("Error Saving Workout", "Client already has a workout scheduled for the selected day." + Environment.NewLine + "Please select a different date to add this workout plan.", "OK"); return; } var answer = await DisplayAlert("Add Workout Plan", "Are you sure you want to add the " + selectedPlan.name + " plan's workout to this client?", "Yes", "No"); if (!answer) { return; } //get all workoutIDs from Plan int loopCounter = 1; DateTime selectedDate = scheduledDate.Date; List <int> allWorkoutIDs = App.Database.getAllWorkoutIDsFromWorkoutPlan(selectedPlan); foreach (int i in allWorkoutIDs) { ClientWorkouts workouts = new ClientWorkouts(0, pkClientID, 0, selectedDate); ClientWorkoutsViewModel tempViewModel = new ClientWorkoutsViewModel(workouts.ID, workouts.clientID, workouts.workoutID, workouts.scheduledDate, workouts.completedDate, "", ""); workouts.workoutID = allWorkoutIDs[loopCounter - 1]; if (loopCounter == 1) { //do nothing } else { if (App.Database.verifyClientWorkoutDates(tempViewModel) > 0) { do { selectedDate = selectedDate.AddDays(1); workouts.scheduledDate = selectedDate; tempViewModel.scheduledDate = selectedDate; } while (App.Database.verifyClientWorkoutDates(tempViewModel) > 0); } } await App.Database.saveClientWorkout(workouts); selectedDate = selectedDate.AddDays(1); loopCounter += 1; } await Navigation.PopAsync(); }