コード例 #1
0
        /// <inheritdoc/>
        public async Task <ExcerciseResponse> PutExcercise(Guid id, ExcerciseRequest request)
        {
            _logger.LogInformation($"{nameof(ExcerciseService)} - {nameof(PutExcercise)} - Started, " +
                                   $"{nameof(id)}: {id}, " +
                                   $"{nameof(ExcerciseRequest)}: {JsonConvert.SerializeObject(request)}");

            var excercise = await _excerciseRepository.Get(id);

            if (excercise == null)
            {
                _logger.LogInformation($"{nameof(ExcerciseService)} - {nameof(PutExcercise)} - " +
                                       $"{nameof(excercise)} not found, " +
                                       $"{nameof(id)}: {id}, " +
                                       $"{nameof(ExcerciseRequest)}: {JsonConvert.SerializeObject(request)}");
                throw new StatusCodeException(HttpStatusCode.NotFound, $"{nameof(excercise)} not found");
            }

            _mapper.Map(request, excercise);
            excercise = await _excerciseRepository.Update(excercise);

            _logger.LogInformation($"{nameof(ExcerciseService)} - {nameof(PutExcercise)} - Finished, " +
                                   $"{nameof(id)}: {id}, " +
                                   $"{nameof(ExcerciseRequest)}: {JsonConvert.SerializeObject(request)}");
            return(_mapper.Map <ExcerciseResponse>(excercise));;
        }
コード例 #2
0
        public async Task <IActionResult> PostExcercise([FromBody] ExcerciseRequest request)
        {
            _logger.LogInformation($"{nameof(ExcerciseController)} - {nameof(PostExcercise)} - Started, " +
                                   $"{nameof(ExcerciseRequest)}: {JsonConvert.SerializeObject(request)}");

            var result = await _excerciseService.PostExcercise(request);

            _logger.LogInformation($"{nameof(ExcerciseController)} - {nameof(PostExcercise)} - Finished, " +
                                   $"{nameof(ExcerciseRequest)}: {JsonConvert.SerializeObject(request)}");
            return(StatusCode(StatusCodes.Status201Created, result));
        }
コード例 #3
0
        /// <inheritdoc/>
        public async Task <ExcerciseResponse> PostExcercise(ExcerciseRequest request)
        {
            _logger.LogInformation($"{nameof(ExcerciseService)} - {nameof(PostExcercise)} - Started, " +
                                   $"{nameof(ExcerciseRequest)}: {JsonConvert.SerializeObject(request)}");

            var excercise = _mapper.Map <Excercise>(request);

            excercise = await _excerciseRepository.Add(excercise);

            if (excercise == null)
            {
                _logger.LogError($"{nameof(ExcerciseService)} - {nameof(PostExcercise)} - " +
                                 $"{nameof(excercise)} already exists" +
                                 $"{nameof(ExcerciseRequest)}: {JsonConvert.SerializeObject(request)}");
                throw new StatusCodeException(HttpStatusCode.Conflict, $"{nameof(excercise)} already exists");
            }

            _logger.LogInformation($"{nameof(ExcerciseService)} - {nameof(PostExcercise)} - Finished, " +
                                   $"{nameof(ExcerciseRequest)}: {JsonConvert.SerializeObject(request)}");
            return(_mapper.Map <ExcerciseResponse>(excercise));;
        }