public async Task RequestUpdateEmail(UpdateUSerEmailAccountDto userParams, string idUser, IUrlHelper url)
        {
            if (userParams == null || idUser == null)
            {
                throw new AppException("The data provided is not correct");
            }

            var user = await _userManager.FindByIdAsync(idUser);

            if (user == null)
            {
                throw new AppException("Utilizador Invalido!");
            }

            //if (userParams.Email.Equals(user.Email, StringComparison.InvariantCultureIgnoreCase))
            //    throw new AppException("O seu novo email e o mesmo da sua actual conta! Por favor indique um email diferente.");

            //var userEntityUsername = await _userManager.FindByEmailAsync(userParams.Email);
            //    if (userEntityUsername != null)
            //        throw new AppException("Email is already assigned to another user!");

            var token = await _userManager.GenerateChangeEmailTokenAsync(user, userParams.Email);

            var resetLink = url.Action("UpdateEmailConfirmationTokenAsync", "Account",
                                       new { token = token, userId = user.Id, newEmail = userParams.Email }, protocol: _httpContext.HttpContext.Request.Scheme);

            Helpers.SendGrid sendEmail = new Helpers.SendGrid(_configuration);

            await sendEmail.PostMessageUpdateEmail(userParams.Email, resetLink);
        }
        public async Task <IActionResult> RequestUpdateEmailAsync(string id, [FromBody] UpdateUSerEmailAccountDto updateUserPasswordDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState.Values.SelectMany(v => v.Errors).Select(modelError => modelError.ErrorMessage).ToList()));
                }

                // save
                await _accountService.RequestUpdateEmail(updateUserPasswordDto, id, Url);

                return(Ok(new { message = "Por favor consulte o seu email para confirmar a alteração!" }));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }