示例#1
0
        public IEnumerable<IResult> Save()
        {
            if (String.IsNullOrWhiteSpace(CurrentPassword) ||
                String.IsNullOrWhiteSpace(NewPin) ||
                String.IsNullOrWhiteSpace(ConfirmPin))
            {
                if (String.IsNullOrWhiteSpace(CurrentPassword))
                    AddError("CurrentPassword", "Current Password is required.");

                if (String.IsNullOrWhiteSpace(NewPin))
                    AddError("NewPin", "New PIN is required.");

                if (String.IsNullOrWhiteSpace(ConfirmPin))
                    AddError("ConfirmPin", "Confirm PIN is required.");

                yield break;
            }

            if (NewPin != ConfirmPin)
            {
                AddError("NewPin", "PINs do not match.");
                AddError("ConfirmPin", "PINs do not match.");
                yield break;
            }

            var pinRegex = new Regex(@"^\d{4,10}$");
            if (!pinRegex.IsMatch(NewPin))
            {
                AddError("NewPin", "PIN must be between 4 to 10 digits.");
                AddError("ConfirmPin", "PIN must be between 4 to 10 digits.");
                yield break;
            }

            BusyOn("Validating Current Password");
            var validPasswordRequest = new GetValidPasswordRequest(CurrentPassword);
            yield return validPasswordRequest;
            BusyOff();

            if (validPasswordRequest.Error != null)
            {
                yield return new HandleExceptionResult(validPasswordRequest.Error);
                yield break;
            }

            if (validPasswordRequest.Result == false)
            {
                AddError("CurrentPassword", "Current Password is invalid.");
                yield break;
            }

            BusyOn("Saving New Pin");
            var saveNewPinRequest = new SaveNewPinRequest(NewPin);
            yield return saveNewPinRequest;
            BusyOff();

            if (saveNewPinRequest.Error != null)
            {
                yield return new HandleExceptionResult(saveNewPinRequest.Error);
                yield break;
            }

            ReturnObject = true;

            base.Close();
        }
        public IEnumerable<IResult> Save()
        {
            if (String.IsNullOrWhiteSpace(CurrentPassword) ||
                String.IsNullOrWhiteSpace(NewPassword) ||
                String.IsNullOrWhiteSpace(ConfirmPassword))
            {
                if (String.IsNullOrWhiteSpace(CurrentPassword))
                    AddError("NewPassword", "Current Password is required.");

                if (String.IsNullOrWhiteSpace(NewPassword))
                    AddError("NewPassword", "New Password is required.");

                if (String.IsNullOrWhiteSpace(ConfirmPassword))
                    AddError("ConfirmPassword", "Confirm Password is required.");

                yield break;
            }

            if (NewPassword != ConfirmPassword)
            {
                AddError("NewPassword", "Passwords do not match.");
                AddError("ConfirmPassword", "Passwords do not match.");
                yield break;
            }

            BusyOn("Validating Current Password");
            var validPasswordRequest = new GetValidPasswordRequest(CurrentPassword);
            yield return validPasswordRequest;
            BusyOff();

            if (validPasswordRequest.Error != null)
            {
                yield return new HandleExceptionResult(validPasswordRequest.Error);
                yield break;
            }

            if (validPasswordRequest.Result == false)
            {
                AddError("CurrentPassword", "Current Password is invalid.");
                yield break;
            }

            BusyOn("Saving New Password");
            var saveNewPasswordRequest = new SaveNewPasswordRequest(NewPassword);
            yield return saveNewPasswordRequest;
            BusyOff();

            if (saveNewPasswordRequest.Error != null)
            {
                yield return new HandleExceptionResult(saveNewPasswordRequest.Error);
                yield break;
            }

            ReturnObject = true;

            base.Close();
        }