private void PrepareExercisesButtons(bool loadAllExcercises) { IList <exercis> listOfExercises = new List <exercis>(); if (loadAllExcercises) { var lessons = _lessonService.GetLessonsByUser(_user); listOfExercises = _exerciseService.GetAllExercisesByUserLessons(lessons); } else if (_lesson != null) { listOfExercises = _exerciseService.GetExercisesByUserSingleLesson(_lesson); } else if (_exerciseNumber != 0) { listOfExercises = _exerciseService.GetAllExercisesFromLesson(_user, _exerciseNumber); } foreach (exercis exercise in listOfExercises) { Button exerciseButton = new Button { Content = GlobalVariables.exerciseNumberPartialText + exercise.exercise_number }; exerciseButton.Click += new RoutedEventHandler(ExerciseButton_Click); exerciseButton.CustomizeAsExerciseButton(); SetExerciseButtonEnabledOrDisabled(exerciseButton); this.excercisesButtonStackPanel.Children.Add(exerciseButton); } }