Exemple #1
0
        async void SendWorkoutRequest()
        {
            if (setsGrid.Children.ToList().Where(child => Grid.GetRow(child) > 0).Count() == 0)
            {
                await DisplayAlert("Error!", "Please Fill the Fields first", "Ok");

                return;
            }

            Request addWorkoutRequest = new Request();

            workout myWorkout = new workout();

            myWorkout.workOutDes     = workoutNoteTxt.Text;
            myWorkout.workoutTrainee = player.userId;

            excercise        excersise     = new excercise();
            List <excercise> excerciseList = new List <excercise>();

            var allChildren = setsGrid.Children.ToList();

            for (int i = 1; i < rows; i++)
            {
                var childs = allChildren.Where(child => Grid.GetRow(child) == i);
                excersise = new excercise();
                string reps   = "";
                string weight = "";
                string muscle = "";
                foreach (var child in childs)
                {
                    //excerciseDesc = " excercise no " + i + "  is : ";
                    if (child is Entry)
                    {//validations
                        var view = (Entry)child;

                        if (Grid.GetColumn(child) == 1)
                        {
                            reps = string.IsNullOrEmpty(view.Text) ? "" : view.Text;
                        }

                        else if (Grid.GetColumn(child) == 2)
                        {
                            weight = string.IsNullOrEmpty(view.Text) ? "" : view.Text;
                        }
                    }

                    else if (child is Picker)
                    {
                        var view = (Picker)child;

                        muscle = view.SelectedItem.ToString();
                    }
                }
                excersise.excericeId          = i;
                excersise.excericeDescreption = "Excercise " + i + " is ";
                if (!string.IsNullOrEmpty(reps))
                {
                    excersise.excericeDescreption += reps +
                                                     " Reps ";
                }
                if (!string.IsNullOrEmpty(weight))
                {
                    excersise.excericeDescreption += "with " + weight + "kg";
                }

                excersise.excericeDescreption += "  for " + muscle;
                excerciseList.Add(excersise);
            }

            // excersiseList.Remove(excersiseList.Last());
            myWorkout.workoutExcerices = excerciseList;
            string workoutStr = JsonConvert.SerializeObject(myWorkout);

            var response = await addWorkoutRequest.callService("Workout/addworkout", workoutStr, "POST");

            if (response.status == true)
            {
                if (response.content == "STATUS:-3")
                {
                    await DisplayAlert("Error!", "Server Error has occured please try again later!", "Ok");

                    return;
                }

                else if (response.content == "STATUS:-1")
                {
                    await DisplayAlert("Error!", " Invalid Parameters Please enter valid info", "Ok");

                    return;
                }

                await DisplayAlert("Published!", "Your work out has been published successfully", "Ok");

                clearFields();
            }

            else
            {
                await DisplayAlert("Error", "Network Error!", "Ok");
            }
        }
Exemple #2
0
        async void CallSubmitWorkoutService()
        {
            if (setsGrid.Children.ToList().Where(child => Grid.GetRow(child) > 0).Count() == 0)
            {
                await DisplayAlert("Error!", "Please Fill the Fields first", "Ok");

                return;
            }



            Request addWorkoutRequest = new Request();

            workout myWorkout = new workout();

            myWorkout.workOutDes     = workoutNoteTxt.Text;
            myWorkout.workoutTrainee = Playeruser.userId;

            excercise        excersise     = new excercise();
            List <excercise> excerciseList = new List <excercise>();

            var allChildren = setsGrid.Children.ToList();

            for (int i = 1; i < rows; i++)
            {
                var childs = allChildren.Where(child => Grid.GetRow(child) == i);
                excersise = new excercise();
                string activity = "";
                string distance = "";
                string duration = "";
                foreach (var child in childs)
                {
                    if (child is Picker)
                    {
                        var view = (Picker)child;

                        activity = view.SelectedItem.ToString();
                    }



                    else if (child is Entry)
                    {
                        var view = (Entry)child;

                        if (Grid.GetColumn(child) == 2)
                        {
                            distance =
                                string.IsNullOrEmpty(view.Text) ? "": view.Text.ToString();
                        }

                        else if (Grid.GetColumn(child) == 3)
                        {
                            duration = string.IsNullOrEmpty(view.Text) ? "" : view.Text.ToString();
                        }
                    }
                }
                excersise.excericeId          = i;
                excersise.excericeDescreption = "Excercise " + i + " is " + activity;
                if (!string.IsNullOrEmpty(distance))
                {
                    excersise.excericeDescreption +=

                        "  distance of " + distance + "km ";
                }

                if (!string.IsNullOrEmpty(duration))
                {
                    excersise.excericeDescreption += " for " +
                                                     duration + "  minutes";
                }

                excerciseList.Add(excersise);
            }

            myWorkout.workoutExcerices = excerciseList;
            string workoutStr = JsonConvert.SerializeObject(myWorkout);

            var res = await addWorkoutRequest.callService("Workout/addworkout", workoutStr, "POST");

            if (res.status == true)
            {
                if (res.content == "STATUS:-3")
                {
                    await DisplayAlert("Error!", "Server Error has occured please try again later!", "Ok");

                    return;
                }

                else if (res.content == "STATUS:-1")
                {
                    await DisplayAlert("Error!", " Invalid Parameters Please enter valid info", "Ok");

                    return;
                }
                await DisplayAlert("Published!", "Your work out has been published successfully", "Ok");

                clearFields();
            }
            else
            {
                await DisplayAlert("Error", "Network Error!", "Ok");
            }
        }