public async Task <IActionResult> AddColor([FromBody] NewColorDto newColor) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await _colorRepository.IsDuplicateColorAsync(newColor)) { ModelState.AddModelError("color", "Color already exists"); return(BadRequest(ModelState)); } var colorId = await _colorRepository.AddColorAsync(newColor); if (colorId > 0) { return(Ok(colorId)); } return(StatusCode(500, "An error ocurred in server")); } catch (Exception e) { _logger.LogCritical($"POST {Route} - {e.GetType().Name} - {e.Message} - {e.StackTrace}"); return(StatusCode(500, "An error ocurred in server")); } }