示例#1
0
        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;
        }
        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();
            }
        }
示例#3
0
 public EditClientWorkout(ClientWorkoutsViewModel clientWorkouts)
 {
     InitializeComponent();
     cClientWorkouts = clientWorkouts;
     this.Title      = "Change Workout Date";
 }
示例#4
0
        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();
        }