public async Task <ActionResult> PostUserRoles(int userId, RoleModel role) { try { var user = await _userService.GetAsync(userId); if (user == null) { return(NotFound("User not found")); } await _userRoleService.AssociateAsync(userId, role); return(Created($"/api/v2/users/{userId}/roles", role)); } catch (System.ApplicationException ex) { return(StatusCode(StatusCodes.Status422UnprocessableEntity, ex.Message)); } catch (System.Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "A server error has occurred")); } }