public async Task <WorkoutDisplayDTO> Handle(GetWorkoutForDisplayQuery request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("GetWorkoutForDisplayQueryHandler");

            FitnessTracker.Domain.Workout.Workout workout = await _repository.GetWorkoutForDisplayAsync(request.Id).ConfigureAwait(false);

            var lastSavedWorkout = await _repository.GetLastSavedWorkout(request.Id).ConfigureAwait(false);

            workout.DailyWorkout.Add(lastSavedWorkout);

            return(AsyncHelper.RunSync <WorkoutDisplayDTO>(() => MakeWorkoutDTO(workout)));
        }
Ejemplo n.º 2
0
        public async Task <Domain.Workout.Workout> SaveWorkoutAsync(Domain.Workout.Workout workout)
        {
            // very weird, the code above saves the reps out of order.  The code below was used in the orginal version and it for some reason saves the reps in the correct order
            FitnessTracker.Domain.Workout.Workout newworkout = new FitnessTracker.Domain.Workout.Workout
            {
                Name     = workout.Name,
                isActive = true
            };

            await _dbContext.Workout.AddAsync(newworkout);

            await SaveChangesAsync();

            foreach (var newSet in workout.Set)
            {
                newworkout.Set.Add(newSet);
                await SaveChangesAsync();
            }

            return(newworkout);
        }