public async Task <IActionResult> ChangeEmail([FromRoute] string username, [FromBody] ClientChangeEmailRequest request) { if (request == null || (!ModelState.IsValid)) { return(BadRequest("Request model is not correct")); } var userRole = HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Role").Value.ToString(); var userNameFromJwt = HttpContext.User.Claims.FirstOrDefault(x => x.Type == "UserName").Value.ToString(); if (userNameFromJwt == username || userRole == "admin") { var changeResponse = await _clientDataService.ChangeEmailAsync(username, request.NewEmail); if (!changeResponse.Success) { return(BadRequest(changeResponse.ErrorsMessages)); } return(Ok("Email chage is successful")); } else { return(Forbid()); } }