Пример #1
0
        public IActionResult Update(Guid id, [FromBody] RoutineRequest request)
        {
            var routine = trainingRepository.GetRoutine(id);

            if (routine.UserId != CurrentUserId)
            {
                return(Unauthorized());
            }
            CreateExercises(request.Workouts.SelectMany(w => w.Exercises));
            Mapper.Map(request, routine);
            trainingRepository.UpdateRoutine(routine);

            var response = Mapper.Map <RoutineDetailsResponse>(routine);

            return(Ok(response));
        }
Пример #2
0
        public IActionResult Create([FromBody] RoutineRequest request)
        {
            CreateExercises(request.Workouts.SelectMany(w => w.Exercises));
            var routine = Mapper.Map <RoutineDetails>(request);

            routine.UserId = CurrentUserId;
            if (!trainingRepository.SearchRoutines(CurrentUserId).Any())
            {
                routine.Active = true;
            }
            trainingRepository.CreateRoutine(routine);

            var response = Mapper.Map <RoutineDetailsResponse>(routine);

            return(Ok(response));
        }