예제 #1
0
        public async Task <User> ChangePassword(User user, string newPassword)
        {
            // Xác thực dữ liệu thay đổi password
            if (!await UserValidator.Update(user, newPassword))
            {
                return(user);
            }

            using (UOW.Begin())
            {
                try
                {
                    UserFilter filter = new UserFilter
                    {
                        Username = user.Username,
                        Password = user.Password
                    };
                    user = await UOW.UserRepository.Get(filter);

                    user.Password = newPassword;

                    await UOW.UserRepository.Update(user);

                    await UOW.Commit();

                    return(await UOW.UserRepository.Get(new UserFilter
                    {
                        Username = user.Username,
                        Password = newPassword
                    }));
                }
                catch (Exception e)
                {
                    await UOW.Rollback();

                    user.AddError(nameof(UserService), nameof(ChangePassword), Common.ErrorCode.SystemError);
                    return(user);
                }
            }
        }