public async Task <int> CreateWorkout(WorkoutBody workoutBody)
        {
            // create workout exercises
            List <WorkoutExercise> exercises = new List <WorkoutExercise>();

            foreach (int exerciseId in workoutBody.Exercises)
            {
                // if the exercise does not exist
                if (!await exerciseRepository.ExerciseExists(exerciseId))
                {
                    continue;
                }

                exercises.Add(new WorkoutExercise
                {
                    ExerciseId = exerciseId
                });
            }

            // create new workout
            Workout newWorkout = new Workout
            {
                Name      = workoutBody.Name,
                Type      = workoutBody.Type,
                Exercises = exercises
            };

            // save workout to database
            await workoutRepository.CreateAsync(newWorkout);

            return(newWorkout.Id);
        }
        public async Task <Workout> UpdateWorkout(WorkoutBody workoutBody, int workoutId)
        {
            Workout oldWorkout = await workoutRepository.ReadAsync(workoutId);

            // create workout
            Workout workout = new Workout
            {
                Id   = workoutId,
                Name = workoutBody.Name,
                Type = workoutBody.Type,
            };

            if (workoutBody.Exercises != null)
            {
                // create workout exercises
                List <WorkoutExercise> exercises = new List <WorkoutExercise>();
                foreach (int exerciseId in workoutBody.Exercises)
                {
                    exercises.Add(new WorkoutExercise
                    {
                        ExerciseId = exerciseId
                    });
                }
                workout.Exercises = exercises;
            }

            // save workout to database
            Workout updatedWorkout = await workoutRepository.UpdateAsync(workout);

            return(updatedWorkout);
        }