/// <summary>
        ///     Directs to a page to edit a specific workout.
        /// </summary>
        /// <param name="id"> Id of workout</param>
        /// <returns> Edit page of workout</returns>
        public async Task <IActionResult> EditWorkout(int id)
        {
            var workoutToUpdate = await _workoutService.GetWorkoutAsync(id);

            var exercises = await _exerciseService.GetAllExercisesAsync();

            if (workoutToUpdate == null || exercises == null)
            {
                return(View("/Error"));
            }

            var model = _mapper.Map <WorkoutViewModel>(workoutToUpdate);

            model.Exercises      = exercises.ToList() ?? new List <ExerciseDto>(); // Add exercises or empty list if null
            model.WorkoutEntries =
                _mapper.Map <ICollection <WorkoutEntryDto>, IEnumerable <WorkoutEntryViewModel> >(workoutToUpdate
                                                                                                  .WorkoutEntryDtos);

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetWorkout(long Id)
        {
            var workout = await _workoutService.GetWorkoutAsync(Id);

            return(Ok(workout));
        }