public IActionResult Register([FromBody] Rider rider) { try { //if (ModelState.IsValid) { if (_service.UserNameExists(rider.UserName)) { return(Unauthorized()); } // A valid new rider to be added AuthorizationResponseData ResponseData = _service.AddRiderWAuthorization(rider); return(Ok(ResponseData)); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(BadRequest("Unable to save changes. Try again.")); }