Exemple #1
0
        public async Task <string> ResetPasswordByAdminAsync(int userId)
        {
            var login = await _unitOfWork.GetRepository <ADUser>()
                        .GetAsync(userId);

            if (login == null)
            {
                throw new EntityNotFoundException();
            }

            int newPassword = RandomHelper.GetRandom(100000, 999999);

            var userFormDb = await _unitOfWork.GetRepository <ADUser>().GetAsync(userId);

            login.ADUserPassword = LoginHelper.EncryptPassword(newPassword.ToString());
            await _unitOfWork.GetRepository <ADUser>().UpdateAsync(login);

            await _unitOfWork.CompleteAsync();

            BackgroundJob.Enqueue(() => _sendEmailService.SendNewPasswordAsync(userFormDb.ADUserEmail, newPassword.ToString()));

            return(newPassword.ToString());
        }