public async Task <IActionResult> InsertNewConsultant(ConsultantVM consultantVM) { try { if (ModelState.IsValid) { consultantVM.UserId = User.FindFirstValue(ClaimTypes.Name); var result = await consultantService.SaveConsultant(consultantVM); if (result == DbStatusCode.Created) { return(Ok(HttpStatusCode.Created)); } else if (result == DbStatusCode.Exception) { return(StatusCode(500)); } else { return(Forbid()); } //We can also return status like below //return StatusCode(403); //Forbidden: 403 } else { return(BadRequest(ModelState)); } } catch (Exception ex) { return(BadRequest(ex.Message ?? ex.InnerException.Message)); } }