private void ChangeIsSelectedAndSend(object parameter) { // Casts the parameter (exercise id) into a string var exerciseId = parameter as string; // Looks into the database for the exercise var exercise = db.Exercises.Where(e => e.Id == exerciseId).FirstOrDefault(); // Creates new List Item var availableExercise = new AvailableExerciseListItemViewModel { Id = exercise.Id, Name = exercise.Name, IsSelected = true, }; // Sends the message to the List View Model MessengerInstance.Send(new PropertyChangedMessage <AvailableExerciseListItemViewModel>(null, availableExercise, "ExerciseSelected")); }
/// <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); } } } }