/** *********** Constructor ******** **/
 public MovieCardViewModel()
 {
     DAOF       = new DAOFacadeSingleton();
     AddComment = new RelayCommand(AddCommentExe, AddCommentCanExe);
     Validator  = new ValidationHelper();
     Validator.AddRequiredRule(() => NoteAdd, "Note obligatoire");
     Validator.AddRequiredRule(() => CommentAdd, "Commentaire obligatoire");
 }
Beispiel #2
0
        /************* Constructor **********/
        public AccountCreatorViewModel()
        {
            DAOF = new DAOFacadeSingleton();

            AccountCreator = new RelayCommand(AccountCreatorExe, AccountCreatorCanExe);
            Validator      = new ValidationHelper();
            Validator.AddRequiredRule(() => Login, "Login obligatoire");
            Validator.AddRequiredRule(() => Mdp, "Mot de passe obligatoire");
        }
Beispiel #3
0
        protected ValidationResult ConfigureValidationRules()
        {
            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => Username, "Username is required.");
            validator.AddRequiredRule(() => Password, "Password is required.");

            return(validator.ValidateAll());
        }
 /************************** Constructor ********************/
 public CreateMovieViewModel()
 {
     DAOF        = new DAOFacadeSingleton();
     CreateMovie = new RelayCommand(CreateMovieExe, CreateMovieCanExe);
     UpdateMovie = new RelayCommand(UpdateMovieExe, UpdateMovieCanExe);
     Validator   = new ValidationHelper();
     Validator.AddRequiredRule(() => Summary, "Sommaire obligatoire");
     Validator.AddRequiredRule(() => Genre, "Genre obligatoire");
     Validator.AddRequiredRule(() => Title, "Titre obligatoire");
 }
Beispiel #5
0
        private bool IsValid()
        {
            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => SelectedGroup.Name, "Name is required.");
            validator.AddRequiredRule(() => SelectedGroup.Description, "Description is required.");

            var result = validator.ValidateAll();

            ValidationErrors = result.AsObservableDictionary();

            return(result.IsValid);
        }
        private bool IsValid()
        {
            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => SelectedPassword.Name, "Name is required.");
            validator.AddRequiredRule(() => SelectedPassword.Secret, "Password is required.");
            validator.AddRequiredRule(() => SelectedPassword.AccessAddress, "URL / Access address is required.");

            var result = validator.ValidateAll();

            ValidationErrors = result.AsObservableDictionary();

            return(result.IsValid);
        }
        private async Task ForgotPin()
        {
            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => EmailInput, "The email is required.");

            if (!Validate(validator))
            {
                return;
            }

            try
            {
                var result = await _requestProvider
                             .PostAsync <UserModel, bool>(GlobalSetting.Instance.ForgotPinEndpoint,
                                                          new UserModel
                {
                    Email = _emailInput,
                    Pin   = (string)Settings.Get(Settings.Key.Pin)
                });

                if (result)
                {
                    await _context.Navigation.PopAsync();

                    _message.LongAlert("PIN has been sent to your email address.");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"--- Error: {e.StackTrace}");
            }
        }
Beispiel #8
0
        private bool ValidateTokenAddress()
        {
            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => ContractAddress, "Token address is required.");
            var resultOne = validator.ValidateAll();

            if (!resultOne.IsValid)
            {
                Errors = resultOne.ErrorList;

                return(resultOne.IsValid);
            }

            bool isValidAddress;

            try
            {
                isValidAddress = new Regex("^(?=.{42}$)0x[a-fA-F0-9]*").IsMatch(ContractAddress);
            }
            catch (Exception e)
            {
                isValidAddress = false;
            }
            validator.AddRule(ContractAddress, () => RuleResult.Assert(isValidAddress, "Token address is not valid Ethereum smart contract address."));

            var result = validator.ValidateAll();

            Errors = result.ErrorList;

            return(result.IsValid);
        }
Beispiel #9
0
        private void ValidateTransaction()
        {
            try
            {
                this._amount = BigDecimal.Parse(this._amountString);
            }
            catch (Exception e)
            {
                this._amount = null;
            }

            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => ReceiverAddress, "Address receiver is required.");
            validator.AddRequiredRule(() => _amount, "Valid amount is required.");
            validator.AddRequiredRule(() => Token, "Select token to send.");

            var resultTemp = validator.ValidateAll();

            if (!resultTemp.IsValid)
            {
                Errors  = resultTemp.ErrorList;
                IsValid = resultTemp.IsValid;
                return;
            }

            bool isValidAddress;

            try
            {
                isValidAddress = new Regex("^(?=.{42}$)0x[a-zA-Z0-9]*").IsMatch(ReceiverAddress);
            }
            catch (Exception e)
            {
                isValidAddress = false;
            }
            validator.AddRule(ReceiverAddress, () => RuleResult.Assert(isValidAddress, "Receiver address is not valid Ethereum account address."));
            validator.AddRule(Amount, () => RuleResult.Assert(this._amount > new BigDecimal(0), "Amount is zero."));
            validator.AddRule(Amount, () => RuleResult.Assert(this._amount < Token.Balance, "You don't have enough funds."));

            var result = validator.ValidateAll();

            Errors = result.ErrorList;

            IsValid = result.IsValid;
        }
        private bool Validate()
        {
            ValidationHelper validator = new ValidationHelper();

            validator.AddRequiredRule(() => ReminderDay, LocalizationManager.GetString("reminder_date_required"));
            validator.AddRequiredRule(() => ReminderTime, LocalizationManager.GetString("reminder_time_required"));
            validator.AddRequiredRule(() => SelectedReminder.Title, LocalizationManager.GetString("reminder_title_required"));

            validator.AddRule("MinimumDate", () =>
            {
                bool condition = true;

                if (_reminderDay.HasValue && !string.IsNullOrEmpty(_reminderTime))
                {
                    var day = _reminderDay.Value;

                    var timeElements = _reminderTime.Split(':');
                    if (timeElements.Length >= 2)
                    {
                        int hour = -1, minute = -1;
                        if (int.TryParse(timeElements[0], out hour))
                        {
                            if (int.TryParse(timeElements[1], out minute))
                            {
                                DateTime newDate = new DateTime(day.Year, day.Month, day.Day, hour, minute, 0, DateTimeKind.Local);
                                newDate          = newDate.ToUniversalTime();

                                long unixDateTime      = ((DateTimeOffset)newDate).ToUnixTimeSeconds();
                                _selectedReminder.Date = unixDateTime;

                                condition = _selectedReminder.Date > ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds();
                            }
                        }
                    }
                }

                return(RuleResult.Assert(condition, LocalizationManager.GetString("date_time_not_past_error")));
            });

            var result = validator.ValidateAll();

            Errors = result.AsObservableDictionary();

            return(result.IsValid);
        }
Beispiel #11
0
        public MainViewModel(IDialogCoordinator dialogCoordinator)
        {
            Validator = new ValidationHelper();

            NotifyDataErrorInfoAdapter = new NotifyDataErrorInfoAdapter(Validator);
            Validator.AddRequiredRule(() => Asset_tag, "Asset Tag is required");
            Validator.AddRequiredRule(() => Selected_resou, "Please Select Resolution");
            Validator.AddRequiredRule(() => Selected_device, "Please Select a Device");
            NotifyDataErrorInfoAdapter.ErrorsChanged += OnErrorsChanged;

            _canExecute        = true;
            _dialogCoordinator = dialogCoordinator;
            Mysql_Status       = mysql_data.live_ping();
            Sqlite_Status      = mysql_data.localDB_ping();


            //Validator.AddRequiredRule(() => Users_SelectedValue, "User is required");
            //Validator.AddRequiredRule(() => Computer_type_value, "Computer Type is required");
            //Validator.AddRequiredRule(() => Selected_channel, "Channel is required");
            //Validator.AddRequiredRule(() => Selected_sku, "SKU is required");
        }
Beispiel #12
0
        private void ValidateToken()
        {
            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => TokenName, "Token name is required.");
            validator.AddRequiredRule(() => TokenSymbol, "Token symbol is required.");
            validator.AddRequiredRule(() => Decimals, "Token decimals is required.");

            if (!string.IsNullOrWhiteSpace(Decimals))
            {
                var isValid = int.TryParse(Decimals, out int temp);
                validator.AddRule(ContractAddress, () => RuleResult.Assert(temp >= 0, "Decimals must be greater than zero."));
                validator.AddRule(ContractAddress, () => RuleResult.Assert(isValid, "Decimals must be valid number."));
            }


            var result = validator.ValidateAll();

            Errors = result.ErrorList;

            IsValid = result.IsValid;
        }
Beispiel #13
0
        private async Task OnPagePhoneNumber()
        {
            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => Country, "Country is required.");
            validator.AddRequiredRule(() => PhoneNumber, "Phone number is required.");

            if (!Validate(validator))
            {
                return;
            }

            try
            {
                var phoneNumber = string.Concat(_country.Trim(), new string(_phoneNumber?.Where(char.IsDigit).ToArray()));
                var result      = await _requestProvider
                                  .PostAsync <UserModel, ResultModel>(GlobalSetting.Instance.RegisterNumberEndpoint,
                                                                      new UserModel { PhoneNumber = phoneNumber });

                validator.AddRule(PhoneNumber,
                                  () => RuleResult.Assert(result.Result, result.Message));

                if (!Validate(validator))
                {
                    return;
                }

                if (result.Result)
                {
                    await _context.Navigation.PushSingleAsync(new PhoneVerificationPage(this));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"--- Error: {e.StackTrace}");
            }
        }
Beispiel #14
0
        public void AddRequiredRule_RuleIsAddedForSpecifiedPropertyName()
        {
            // ARRANGE
            var vm = new DummyViewModel();
            var v  = new ValidationHelper();

            v.AddRequiredRule(() => vm.Foo, "Foo required.");

            // ACT
            var vr = v.Validate(nameof(vm.Foo));

            // VERIFY
            Assert.False(vr.IsValid);
            Assert.Equal(vr.ErrorList[0].ErrorText, "Foo required.");
        }
        public void AddRequiredRule_RuleIsAddedForSpecifiedPropertyName()
        {
            // ARRANGE
            var vm = new DummyViewModel();
            var v = new ValidationHelper();

            v.AddRequiredRule(() => vm.Foo, "Foo required.");

            // ACT
            var vr = v.Validate(nameof(vm.Foo));

            // VERIFY
            Assert.False(vr.IsValid);
            Assert.Equal(vr.ErrorList[0].ErrorText, "Foo required.");
        }
        private bool ValidateMnemonicPhrase()
        {
            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => this.InputMnemonic, "Mnemonic phrase is required.");
            foreach (var func in Validators)
            {
                validator.AddRule(nameof(this.InputMnemonic), () => RuleResult.Assert(func.Value(InputMnemonic), func.Key));
            }

            var result = validator.ValidateAll();

            Errors = result.ErrorList;

            return(result.IsValid);
        }
Beispiel #17
0
        private async Task OnPageSuccessSignup()
        {
            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => VerificationCode, "The verification code is required.");

            if (!Validate(validator))
            {
                return;
            }

            try
            {
                var phoneNumber = string.Concat(_country, new string(_phoneNumber?.Where(char.IsDigit).ToArray()));
                var result      = await _requestProvider
                                  .PostAsync <UserModel, bool>(GlobalSetting.Instance.VerificationCodeEndpoint,
                                                               new UserModel { PhoneNumber = phoneNumber, VerificationCode = _verificationCode });

                validator.AddRule(VerificationCode,
                                  () => RuleResult.Assert(result, "The verification code was incorrect.\nPlease try again."));

                if (!Validate(validator))
                {
                    return;
                }

                await _context.Navigation.PushSingleAsync(
                    new SuccessSignup(
                        new CommonPageSettings
                {
                    HasNavigation = false,
                    HeaderText =
                        "Your identity has been verified." + Environment.NewLine
                        + "You can create your wallet."
                },
                        () => this._context.Navigation.PushSingleAsync(new EnterEmailPage())));

                Settings.Set(Settings.Key.VerificationCode, _verificationCode);
                Settings.Set(Settings.Key.PhoneNumber, phoneNumber);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"--- Error: {e.StackTrace}");
            }
        }
Beispiel #18
0
        public void AddRequiredRule_AddsRuleThatChecksTheObjectNotNullOrEmptyString()
        {
            // ARRANGE
            var validation = new ValidationHelper();
            var dummy      = new DummyViewModel();

            validation.AddRequiredRule(() => dummy.Foo, "Foo cannot be empty");

            // ACT
            var result = validation.ValidateAll();

            // VERIFY
            Assert.False(result.IsValid, "Validation must fail");

            // ACT
            dummy.Foo = "abc";
            var resultAfterCorrection = validation.ValidateAll();

            // VERIFY
            Assert.True(resultAfterCorrection.IsValid, "The result must be valid after the correction of the error");
        }
        public void AddRequiredRule_AddsRuleThatChecksTheObjectNotNullOrEmptyString()
        {
            // ARRANGE
            var validation = new ValidationHelper();
            var dummy = new DummyViewModel();

            validation.AddRequiredRule(() => dummy.Foo, "Foo cannot be empty");

            // ACT
            var result = validation.ValidateAll();

            // VERIFY
            Assert.False(result.IsValid, "Validation must fail");

            // ACT
            dummy.Foo = "abc";
            var resultAfterCorrection = validation.ValidateAll();

            // VERIFY
            Assert.True(resultAfterCorrection.IsValid, "The result must be valid after the correction of the error");
        }
        private async Task OpenPageCreateWallet()
        {
            var validator = new ValidationHelper();

            validator.AddRequiredRule(() => EmailInput, "The email is required.");

            if (!Validate(validator))
            {
                return;
            }

            try
            {
                var result = await _requestProvider
                             .PostAsync <UserModel, ResultModel>(GlobalSetting.Instance.VerificationEmailEndpoint,
                                                                 new UserModel
                {
                    Email            = _emailInput,
                    VerificationCode = Settings.Get(Settings.Key.VerificationCode).ToString(),
                    PhoneNumber      = Settings.Get(Settings.Key.PhoneNumber).ToString()
                });

                validator.AddRule(EmailInput,
                                  () => RuleResult.Assert(result.Result, result.Message));

                if (!Validate(validator))
                {
                    return;
                }

                if (result.Result)
                {
                    await _context.Navigation.PushSingleAsync(new NewUserExistPage());
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"--- Error: {e.StackTrace}");
            }
        }