public async Task <ActionResult <DTOs.Label> > PostAsync([FromBody] DTOs.Label label) { try { if (label == null) { return(BadRequest($"Label object from body is null.")); } // Validate label var(statusCode, msg) = await ValidateLabel(label, isCreation : true); if (statusCode == StatusCodes.Status400BadRequest) { _logger.LogError(msg); return(StatusCode(StatusCodes.Status400BadRequest, msg)); } // Create Label var createdLabel = await _labelRepository.AddLabelAsync(_mapper.Map <Models.Label>(label)); var labelDTO = _mapper.Map <DTOs.Label>(createdLabel); return(CreatedAtRoute("GetLabel", new { id = labelDTO.Id }, labelDTO)); } catch (Exception) { var msg = "Error occurred while creating new label into database."; _logger.LogError(msg); return(StatusCode(StatusCodes.Status500InternalServerError, msg)); } }