After updating to ASP.NET Core 3.0 from 2.2, I am receiving the error:
No route matches the supplied values
This appears right after executing CreateAsync()
. It is triggered by the CreatedAtAction()
method. I tried to set GetByIdAsync()
's attribute to [HttpGet("{id}", Name = "Get")]
, but it didn't work out. I checked other related threads but my code looks fine to me.
// GET: api/Bots/5
[HttpGet("{id}")]
public async Task<ActionResult<BotCreateUpdateDto>> GetByIdAsync([FromRoute] int id)
{
var bot = await _botService.GetByIdAsync(id);
if (bot == null)
{
return NotFound();
}
return Ok(_mapper.Map<BotCreateUpdateDto>(bot));
}
// POST: api/Bots
[HttpPost]
public async Task<ActionResult<BotCreateUpdateDto>> CreateAsync([FromBody] BotCreateUpdateDto botDto)
{
var cryptoPair = await _botService.GetCryptoPairBySymbolAsync(botDto.Symbol);
if (cryptoPair == null)
{
return BadRequest(new { Error = "Invalid crypto pair." });
}
var timeInterval = await _botService.GetTimeIntervalByIntervalAsync(botDto.Interval);
if (timeInterval == null)
{
return BadRequest(new { Error = "Invalid time interval." });
}
var bot = new Bot
{
Name = botDto.Name,
Status = botDto.Status,
CryptoPairId = cryptoPair.Id,
TimeIntervalId = timeInterval.Id
};
try
{
await _botService.CreateAsync(bot);
}
catch (Exception ex)
{
return BadRequest(new { Error = ex.InnerException.Message });
}
return CreatedAtAction(nameof(GetByIdAsync), new { id = bot.Id }, _mapper.Map<BotCreateUpdateDto>(bot));
}