private async Task VerifyReferencedPlannedWorkout(CompletedWorkoutVM viewModel, int userId, bool throwIfNoPlannedWorkout)
        {
            if (throwIfNoPlannedWorkout && !viewModel.PlannedWorkoutId.HasValue)
            {
                throw new RestException(System.Net.HttpStatusCode.BadRequest, "Missing planned workout id.");
            }
            else if (!viewModel.PlannedWorkoutId.HasValue)
            {
                if (viewModel.CompletedRepetitions.Any(x => x.PlannedRepetitionId.HasValue))
                {
                    throw new RestException(System.Net.HttpStatusCode.BadRequest, "Planned repetitions cannot exist if not planned workout exists.");
                }
                return;
            }

            var plannedWorkout = await _plannedWorkoutRepository.GetNoTracking(viewModel.PlannedWorkoutId.Value);

            if (plannedWorkout is null || plannedWorkout.UserId != userId)
            {
                throw new RestException(System.Net.HttpStatusCode.NotFound, "Planned workout not found.");
            }
            if (!VerifyPlannedRepetitionIds(viewModel, plannedWorkout))
            {
                throw new RestException(System.Net.HttpStatusCode.BadRequest, "Not all planned repetitions were found.");
            }
        }
        public async Task <PlannedWorkoutVM> GetSingle(int userId, int workoutId, bool includeReps)
        {
            var user = await Extensions.FindUser(userId, _userRepository, _cache);

            var workout = await _plannedWorkoutRepository.GetNoTracking(workoutId);

            if (workout is null || userId != workout.UserId)
            {
                return(null);
            }
            var defaults = user.GetUserDefaultsForActivity(workout.ActivityType);

            return(new PlannedWorkoutVM(workout, defaults, includeReps));
        }