Beispiel #1
0
        public async void SearchExercise()
        {
            var result = await new BL.BlRouter(EventAggregator).GetExercises(Search);

            ExercisesList.Clear();
            foreach (var exercies in result)
            {
                ExercisesList.Add(exercies);
            }
        }
        private async void AddExercise()
        {
            exercises newExercise = new exercises()
            {
                Id   = Guid.NewGuid().ToString(),
                name = Exercise,
            };

            //put a breakpoint here when you run and inpect the values of the Exercise.
            await exerciseStore.AddItemAsync(newExercise);

            ExercisesList.Add(newExercise);

            Exercise = "";
        }
        /// <summary>
        /// Gets the exercises from the database
        /// </summary>
        private void UpdateExercises(string value)
        {
            // Clears the list just in case
            ExercisesList.Clear();
            if (value == null)
            {
                // Adds every exercise from database
                foreach (var exercise in ExercisesFromDatabase)
                {
                    // Creates list item
                    var availableExercise = new AvailableExerciseListItemViewModel
                    {
                        Id   = exercise.Id,
                        Name = exercise.Name,
                    };
                    // Adds the exercise to the list
                    ExercisesList.Add(availableExercise);
                }
            }
            else
            {
                // Changes the value to uppercase so searching for "ben" can work for "Bench"
                var searchedValue = value.ToUpper();


                foreach (var exercise in ExercisesFromDatabase)
                {
                    // Creates list item
                    var availableExercise = new AvailableExerciseListItemViewModel
                    {
                        Id   = exercise.Id,
                        Name = exercise.Name,
                    };
                    // Looks for the searched phrase
                    if (availableExercise.Name.ToUpper().Contains(searchedValue))
                    {
                        // Adds the exercise to the list
                        ExercisesList.Add(availableExercise);
                    }
                }
            }
        }
        /// <summary>
        /// Looks for the exercises of the selected routine
        /// </summary>

        public void GetExercises(PropertyChangedMessage <string> message)
        {
            // If message's property name matches then continue
            if (message.PropertyName == "GetExercises")
            {
                // Deselects other routines
                MessengerInstance.Send(new PropertyChangedMessage <string>("", message.NewValue, "DeselectRoutines"));

                // Stores the given routine id value
                var currentRoutineId = message.NewValue;
                if (currentRoutineId != null)
                {
                    // Gets the routine exercises from the database
                    var routineExercises = db.RoutineExercises.Where(re => re.Id == currentRoutineId).ToList();
                    if (routineExercises != null)
                    {
                        // Clears the ObservableCollection just in case
                        ExercisesList.Clear();
                        // Adds every exercise to the observable collection
                        foreach (var routineExercise in routineExercises)
                        {
                            // Searches the database for exercise that has the id of the RoutineExercise's exercise id
                            var exerciseFromDatabase = db.Exercises.Where(e => e.Id == routineExercise.ExerciseId).FirstOrDefault();

                            var exercise = new ExerciseListItemViewModel
                            {
                                id           = exerciseFromDatabase.Id,
                                ExerciseName = exerciseFromDatabase.Name
                            };
                            // Adds the exercise to the collection
                            ExercisesList.Add(exercise);
                        }

                        // Clears the list containing routines from the database
                        routineExercises.Clear();
                    }
                }
            }
        }