Exemplo n.º 1
0
        //[ProducesResponseType(StatusCodes.Status422UnprocessableEntity,
        //    Type = typeof(Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary))]
        public async Task <ActionResult <QuoteModel> > CreateQuote([FromBody] QuoteCreationModel quoteCreationModel)
        {
            try
            {
                //fetch the samurai from the db for profle mapping to use
                var samurai = await _samuraiRepository.GetSamuraiAsync(quoteCreationModel.SamuraiId);

                if (samurai == null)
                {
                    return(NotFound());
                }

                var quoteEntity = _mapper.Map <Quote>(quoteCreationModel);
                _quoteRepository.AddQuote(quoteEntity);

                await _quoteRepository.SaveChangeAsync();

                return(CreatedAtRoute("GetQuote",
                                      new { quoteId = quoteEntity.Id },
                                      _mapper.Map <QuoteModel>(quoteEntity)));
            }
            catch (Exception ex)
            {
                _logger.LogError($"{ex.Message}");
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult <SamuraiModel> > GetSamurai(int samuraiId)
        {
            try
            {
                var samurai = await _samuraiRepository.GetSamuraiAsync(samuraiId);

                if (samurai == null)
                {
                    return(NotFound());
                }

                return(Ok(_mapper.Map <SamuraiModel>(samurai)));
            }
            catch (Exception ex)
            {
                _logger.LogError($"{ex.Message}");
                throw;
            }
        }