/// <summary>
        /// Change password
        /// </summary>
        /// <param name="request">Request</param>
        /// <returns>Result</returns>
        public virtual ChangePasswordResult ChangePassword(ChangePasswordRequest request)
        {
            if (request == null)
                throw new ArgumentNullException("request");

            var result = new ChangePasswordResult();
            if (String.IsNullOrWhiteSpace(request.UserName))
            {
                result.AddError("Account.ChangePassword.Errors.UserNameIsNotProvided");
                return result;
            }
            if (String.IsNullOrWhiteSpace(request.NewPassword))
            {
                result.AddError("Account.ChangePassword.Errors.PasswordIsNotProvided");
                return result;
            }

            var customer = _customerService.GetCustomerByEmail(request.UserName);
            if (customer == null)
            {
                result.AddError("Account.ChangePassword.Errors.EmailNotFound");
                return result;
            }

            var requestIsValid = false;
            if (request.ValidateRequest)
            {
                //password
                string oldPwd = "";
                switch (customer.PasswordFormat)
                {
                    case PasswordFormat.Encrypted:
                        oldPwd = _encryptionService.EncryptText(request.OldPassword);
                        break;
                    case PasswordFormat.Hashed:
                        oldPwd = _encryptionService.CreatePasswordHash(request.OldPassword, customer.PasswordSalt);
                        break;
                    default:
                        oldPwd = request.OldPassword;
                        break;
                }

                bool oldPasswordIsValid = oldPwd == customer.Password;
                if (!oldPasswordIsValid)
                    result.AddError("Account.ChangePassword.Errors.OldPasswordDoesntMatch");

                if (oldPasswordIsValid)
                    requestIsValid = true;
            }
            else
                requestIsValid = true;

            //at this point request is valid
            if (requestIsValid)
            {
                switch (request.NewPasswordFormat)
                {
                    case PasswordFormat.Clear:
                        {
                            customer.Password = request.NewPassword;
                        }
                        break;
                    case PasswordFormat.Encrypted:
                        {
                            customer.Password = _encryptionService.EncryptText(request.NewPassword);
                        }
                        break;
                    case PasswordFormat.Hashed:
                        {
                            string saltKey = _encryptionService.CreateSaltKey(5);
                            customer.PasswordSalt = saltKey;
                            customer.Password = _encryptionService.CreatePasswordHash(request.NewPassword, saltKey);
                        }
                        break;
                    default:
                        break;
                }
                customer.PasswordFormat = request.NewPasswordFormat;
                _customerService.UpdateCustomer(customer);
            }

            return result;
        }
        /// <summary>
        /// Change password
        /// </summary>
        /// <param name="request">Request</param>
        /// <returns>Result</returns>
        public virtual ChangePasswordResult ChangePassword(ChangePasswordRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var result = new ChangePasswordResult();

            if (String.IsNullOrWhiteSpace(request.UserName))
            {
                result.AddError("用户名不能为空");
                return(result);
            }
            if (String.IsNullOrWhiteSpace(request.NewPassword))
            {
                result.AddError("新密码不能为空");
                return(result);
            }

            var customer = _customerService.GetCustomerByUsername(request.UserName);

            if (customer == null)
            {
                result.AddError("用户不存在");
                return(result);
            }


            var requestIsValid = false;

            if (request.ValidateRequest)
            {
                //password
                string oldPwd = "";
                switch (customer.PasswordFormat)
                {
                case PasswordFormat.Encrypted:
                    oldPwd = _encryptionService.EncryptText(request.OldPassword);
                    break;

                case PasswordFormat.Hashed:
                    oldPwd = _encryptionService.CreatePasswordHash(request.OldPassword, customer.PasswordSalt);
                    break;

                default:
                    oldPwd = request.OldPassword;
                    break;
                }

                bool oldPasswordIsValid = oldPwd == customer.Password;
                if (!oldPasswordIsValid)
                {
                    result.AddError("原密码不正确");
                }

                if (oldPasswordIsValid)
                {
                    requestIsValid = true;
                }
            }
            else
            {
                requestIsValid = true;
            }


            //at this point request is valid
            if (requestIsValid)
            {
                switch (request.NewPasswordFormat)
                {
                case PasswordFormat.Clear:
                {
                    customer.Password = request.NewPassword;
                }
                break;

                case PasswordFormat.Encrypted:
                {
                    customer.Password = _encryptionService.EncryptText(request.NewPassword);
                }
                break;

                case PasswordFormat.Hashed:
                {
                    string saltKey = _encryptionService.CreateSaltKey(5);
                    customer.PasswordSalt = saltKey;
                    customer.Password     = _encryptionService.CreatePasswordHash(request.NewPassword, saltKey);
                }
                break;

                default:
                    break;
                }
                customer.PasswordFormat = request.NewPasswordFormat;
                _customerService.UpdateCustomer(customer);
            }

            return(result);
        }