private void ConfigureValidationRules()
        {
            Validator.AddRequiredRule(() => LRN, "LRN is required");

            Validator.AddAsyncRule(nameof(LRN),
                                   async() =>
            {
                var _context     = new MorenoContext();
                var result       = await _context.Students.FirstOrDefaultAsync(e => e.LRN == LRN);
                bool isAvailable = result == null;
                return(RuleResult.Assert(isAvailable,
                                         string.Format("LRN {0} is taken. Please choose a different one.", LRN)));
            });

            Validator.AddRequiredRule(() => FirstName, "First Name is required");

            Validator.AddRequiredRule(() => LastName, "Last Name is required");

            Validator.AddRequiredRule(() => MiddleName, "Middle Name is required");

            Validator.AddRequiredRule(() => Gender, "Gender is required");

            Validator.AddRequiredRule(() => Contact, "Contact is required");

            Validator.AddRequiredRule(() => Birthdate, "Birthdate is required");


            Validator.AddRequiredRule(() => Address, "Address is required");

            Validator.AddRequiredRule(() => SchoolYear, "School Year is required");

            Validator.AddRequiredRule(() => SelectedSection, "Section is required");

            Validator.AddRequiredRule(() => SelectedYearLevel, "Year Level is required");
        }
 private void ConfigureValidationRules()
 {
     Validator.AddRequiredRule(() => Username, "Username is required");
     //due to passwordbox restrictions, this won't show on the UI
     Validator.AddRequiredRule(() => Password, "Password is required");
     Validator.AddAsyncRule(nameof(Username),
                            async() => RuleResult.Assert(await IsValidLogin(), "Bad Username or Password"));
 }
Exemplo n.º 3
0
 public EntityObservable(IEntityService service)
 {
     _service = service;
     Validator.AddRequiredRule(() => Name, Resource.Strings.Message_IsRequired);
     Validator.AddAsyncRule(() => Name, async() =>
     {
         bool nameDuplicacy = await Task.Run(() => _service.NameDuplicateAsync(_id, Name));
         return(RuleResult.Assert(!nameDuplicacy, Resource.Strings.Message_AlreadyInUse));
     });
 }
Exemplo n.º 4
0
 void ConfigureRules()
 {
     Validator.AddAsyncRule(() => UpdatePayment, async() =>
     {
         if (SelectedTransaction.Balance < UpdatePayment || UpdatePayment == null)
         {
             return(RuleResult.Invalid("Invalid Payment"));
         }
         else
         {
             return(RuleResult.Valid());
         }
     });
 }
Exemplo n.º 5
0
        public override void Prepare()
        {
            Title.Value            = "Груз";
            LockedWheelsList.Value = new List <int> {
                0, 1, 2, 3, 4
            };
            LockedWheels.Value = 0;

#if DEBUG
            RegistrationNumber.Value = "Х827МН76";
#endif

            Validator.AddAsyncRule(nameof(RegistrationNumber), RegistrationNumberValidator);

            base.Prepare();
        }
        /// <summary>
        /// The ConfigureValidationRules
        /// </summary>
        private void ConfigureValidationRules()
        {
            //            Validator.AddAsyncRule(nameof(LRN),
            //                async () =>
            //                {
            //                    var _context = new MorenoContext();
            //                    var result = await _context.Students.FirstOrDefaultAsync(e => e.LRN == LRN);
            //                    bool isAvailable = result == null;
            //                    return RuleResult.Assert(isAvailable,
            //                        string.Format("LRN {0} is taken. Please choose a different one.", LRN));
            //                });
            Validator.AddRequiredRule(() => Quantity, "Quantity is required");
            Validator.AddAsyncRule(() => Quantity,
                                   async() =>
            {
                if (SelectedProduct.Type.Name == "ft")
                {
                    if (SelectedProduct.Stock >= (Size1 * Size2) * Quantity)
                    {
                        return(RuleResult.Valid());
                    }
                    else
                    {
                        return(RuleResult.Invalid("Out of stock!"));
                    }
                }
                else
                {
                    if (SelectedProduct.Stock >= Quantity)
                    {
                        return(RuleResult.Valid());
                    }
                    else
                    {
                        return(RuleResult.Invalid("Out of stock!"));
                    }
                }
            });

            Validator.AddRequiredRule(() => Description, "Description is required");

            if (IsPieces)
            {
                Validator.AddRequiredRule(() => Size1, "Length is required");
                Validator.AddRequiredRule(() => Size2, "Width is required");
            }
        }
Exemplo n.º 7
0
        private void AddValidationRules()
        {
            Validator.AddRule(() => Name, () => RuleResult.Assert(!string.IsNullOrWhiteSpace(Name), "Name is required"));
            Validator.AddRule(() => Catagory, () => RuleResult.Assert((Catagory != null), "Catagory is required"));
            Validator.AddRule(() => Email, () => RuleResult.Assert(!string.IsNullOrWhiteSpace(Email), "Email is required"));
            Validator.AddRule(() => Email,
                              () =>
            {
                const string regexPattern =
                    @"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
                return(RuleResult.Assert(Regex.IsMatch(Email, regexPattern),
                                         "Email must by a valid email address"));
            });
            Validator.AddAsyncRule(() => Email,
                                   async() => {
                bool isAvailable = await administrationService.CheckEmailIsAvailable(Email, this.artist);



                return(RuleResult.Assert(isAvailable,
                                         string.Format("Email {0} is taken. Please choose a different one.", Email)));
            });
        }
Exemplo n.º 8
0
        private void ConfigureValidationRules()
        {
            Validator.AddRequiredRule(() => UserName, "User Name is required");

            Validator.AddAsyncRule(nameof(UserName),
                                   async() =>
            {
                var isAvailable = await UserRegistrationService.IsUserNameAvailable(UserName).ToTask();

                return(RuleResult.Assert(isAvailable,
                                         string.Format("User Name {0} is taken. Please choose a different one.", UserName)));
            });

            Validator.AddRequiredRule(() => FirstName, "First Name is required");

            Validator.AddRequiredRule(() => LastName, "Last Name is required");

            Validator.AddRequiredRule(() => Email, "Email is required");

            Validator.AddRule(nameof(Email),
                              () =>
            {
                const string regexPattern =
                    @"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
                return(RuleResult.Assert(Regex.IsMatch(Email, regexPattern),
                                         "Email must by a valid email address"));
            });

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

            Validator.AddRule(nameof(Password),
                              () => RuleResult.Assert(Password.Length >= 6,
                                                      "Password must contain at least 6 characters"));

            Validator.AddRule(nameof(Password),
                              () => RuleResult.Assert((!Password.All(char.IsLower) &&
                                                       !Password.All(char.IsUpper) &&
                                                       !Password.All(char.IsDigit)),
                                                      "Password must contain both lower case and upper case letters"));

            Validator.AddRule(nameof(Password),
                              () => RuleResult.Assert(Password.Any(char.IsDigit),
                                                      "Password must contain at least one digit"));

            Validator.AddRule(nameof(PasswordConfirmation),
                              () =>
            {
                if (!string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(PasswordConfirmation))
                {
                    return(RuleResult.Invalid("Please confirm password"));
                }

                return(RuleResult.Valid());
            });

            Validator.AddRule(nameof(Password),
                              nameof(PasswordConfirmation),
                              () =>
            {
                if (!string.IsNullOrEmpty(Password) && !string.IsNullOrEmpty(PasswordConfirmation))
                {
                    return(RuleResult.Assert(Password == PasswordConfirmation, "Passwords do not match"));
                }

                return(RuleResult.Valid());
            });

            Validator.AddChildValidatable(() => InterestSelectorViewModel);
        }
        private void ConfigureValidationRules()
        {
            Validator.AddRule(nameof(FirstName),
                              () => RuleResult.Assert(!string.IsNullOrEmpty(FirstName) && FirstName.Length <= 25, "First Name is required and cannot be more than 25 characters"));

            Validator.AddRule(nameof(MiddleName),
                              () => RuleResult.Assert(string.IsNullOrEmpty(MiddleName) || MiddleName.Length <= 25, "Middle Name cannot be more than 25 characters"));

            Validator.AddRule(nameof(LastName),
                              () => RuleResult.Assert(!string.IsNullOrEmpty(LastName) && LastName.Length <= 25, "Last Name is required and cannot be more than 25 characters"));

            Validator.AddRule(nameof(NickName),
                              () => RuleResult.Assert(string.IsNullOrEmpty(NickName) || NickName.Length <= 40, "Alias cannot be more than 40 characters"));

            Validator.AddRequiredRule(() => FollowUpSettings.PreferredContactMethod, "Contact Preference is required");

            Validator.AddAsyncRule(() => Email,
                                   async() =>
            {
                var verifyViaService = (!Email.EmailVerified || (Email.EmailAddress != _originalProspect.Email.EmailAddress)) &&
                                       !String.IsNullOrEmpty(Email.EmailAddress);
                var result = !verifyViaService
                                           ? new EmailValidationResult()
                {
                    IsValid = true
                }
                                           : await _emailValidationService.Validate(Email);

                return(RuleResult.Assert(result.IsValid,
                                         string.Format("Valid email required" + (result.DidYouMean != null ? ". Did you mean " + result.DidYouMean : ""))));
            });

            Validator.AddAsyncRule(() => MobilePhone,
                                   async() =>
            {
                var verifyViaService = (!MobilePhone.PhoneVerified || (MobilePhone.Phone != _originalProspect.MobilePhoneNumber.Phone)) &&
                                       !String.IsNullOrEmpty(MobilePhone.Phone);
                var result = !verifyViaService ? true :
                             await _phoneNumberValidationService.Validate(MobilePhone);

                return(RuleResult.Assert(result,
                                         string.Format("Mobile Phone number is invalid")));
            });

            Validator.AddAsyncRule(() => HomePhone,
                                   async() =>
            {
                var verifyViaService = (!HomePhone.PhoneVerified || (HomePhone.Phone != _originalProspect.HomePhoneNumber.Phone)) &&
                                       !String.IsNullOrEmpty(HomePhone.Phone);
                var result = !verifyViaService ? true :
                             await _phoneNumberValidationService.Validate(HomePhone);

                return(RuleResult.Assert(result,
                                         string.Format("Home Phone number is invalid")));
            });

            Validator.AddAsyncRule(() => WorkPhone,
                                   async() =>
            {
                var verifyViaService = (!WorkPhone.PhoneVerified || (WorkPhone.Phone != _originalProspect.WorkPhoneNumber.Phone)) &&
                                       !String.IsNullOrEmpty(WorkPhone.Phone);
                var result = !verifyViaService ? true :
                             await _phoneNumberValidationService.Validate(WorkPhone);

                return(RuleResult.Assert(result,
                                         string.Format("Work Phone number is invalid")));
            });

            Validator.AddAsyncRule(() => StreetAddress,
                                   async() =>
            {
                var verifyViaService = (!StreetAddress.StreetAddressVerified ||
                                        (StreetAddress.AddressLine1 != _originalProspect.StreetAddress.AddressLine1) ||
                                        (StreetAddress.AddressLine2 != _originalProspect.StreetAddress.AddressLine2) ||
                                        (StreetAddress.City != _originalProspect.StreetAddress.City) ||
                                        (StreetAddress.State != _originalProspect.StreetAddress.State) ||
                                        (StreetAddress.PostalCode != _originalProspect.StreetAddress.PostalCode)) &&
                                       (!String.IsNullOrEmpty(StreetAddress.AddressLine1) ||
                                        !String.IsNullOrEmpty(StreetAddress.AddressLine2) ||
                                        !String.IsNullOrEmpty(StreetAddress.City) ||
                                        !String.IsNullOrEmpty(StreetAddress.State) ||
                                        !String.IsNullOrEmpty(StreetAddress.PostalCode));

                var result = !verifyViaService
                                           ? true :
                             await _streetValidationService.Validate(StreetAddress);

                return(RuleResult.Assert(result,
                                         string.Format("Street Address is invalid")));
            });

            Validator.AddRule(() => ActiveTrafficSourceDetail,
                              () =>
            {
                var result = !(Prospect.ProspectCommunity.LeadId == 0 && (ActiveTrafficSourceDetail == null || ActiveTrafficSourceDetail.CodeId == 0));

                return(RuleResult.Assert(result, string.Format("Traffic Detail required")));
            });

            Validator.AddRule(() => Prospect,
                              () =>
            {
                var result = !(String.IsNullOrEmpty(Email.EmailAddress) &&
                               String.IsNullOrEmpty(MobilePhone.Phone) &&
                               String.IsNullOrEmpty(HomePhone.Phone) &&
                               String.IsNullOrEmpty(WorkPhone.Phone) &&
                               String.IsNullOrEmpty(StreetAddress.AddressLine1) &&
                               String.IsNullOrEmpty(StreetAddress.AddressLine2) &&
                               String.IsNullOrEmpty(StreetAddress.City) &&
                               String.IsNullOrEmpty(StreetAddress.State) &&
                               String.IsNullOrEmpty(StreetAddress.PostalCode));

                return(RuleResult.Assert(result, string.Format("Enter Full Street Address or Phone Number or Email")));
            });

            Validator.AddRule(() => FollowUpSettings,
                              () =>
            {
                var result = !(!FollowUpSettings.ConsentToEmail &&
                               !FollowUpSettings.ConsentToPhone &&
                               !FollowUpSettings.ConsentToMail &&
                               !FollowUpSettings.ConsentToText && !FollowUpSettings.ExcludeFromFollowup);

                return(RuleResult.Assert(result, string.Format("Must Consent or Exclude From Follow Up")));
            });

            Validator.AddRule(() => FollowUpSettings,
                              () =>
            {
                var result = !((FollowUpSettings.ConsentToEmail ||
                                FollowUpSettings.ConsentToPhone ||
                                FollowUpSettings.ConsentToMail ||
                                FollowUpSettings.ConsentToText) && FollowUpSettings.ExcludeFromFollowup);

                return(RuleResult.Assert(result, string.Format("Cannot Consent and Exclude From Follow Up")));
            });

            Validator.AddRule(() => FollowUpSettings,
                              () =>
            {
                var result = !(!FollowUpSettings.ConsentToEmail &&
                               FollowUpSettings.PreferredContactMethod.Equals("Email") && !FollowUpSettings.ExcludeFromFollowup);

                return(RuleResult.Assert(result, string.Format("Must Consent To Email when Contact Preference is Email")));
            });

            Validator.AddRule(() => FollowUpSettings,
                              () =>
            {
                var result = !(!FollowUpSettings.ConsentToPhone &&
                               FollowUpSettings.PreferredContactMethod.Equals("Phone") && !FollowUpSettings.ExcludeFromFollowup);

                return(RuleResult.Assert(result, string.Format("Must Consent To Phone when Contact Preference is Phone")));
            });

            Validator.AddRule(() => FollowUpSettings,
                              () =>
            {
                var result = !(!FollowUpSettings.ConsentToMail &&
                               FollowUpSettings.PreferredContactMethod.Equals("Mail") && !FollowUpSettings.ExcludeFromFollowup);

                return(RuleResult.Assert(result, string.Format("Must Consent To Mail when Contact Preference is Mail")));
            });

            Validator.AddRule(() => FollowUpSettings,
                              () =>
            {
                var result = !(!FollowUpSettings.ConsentToText &&
                               FollowUpSettings.PreferredContactMethod.Equals("Text") && !FollowUpSettings.ExcludeFromFollowup);

                return(RuleResult.Assert(result, string.Format("Must Consent To Text when Contact Preference is Text")));
            });

            Validator.AddRule(() => FollowUpSettings,
                              () =>
            {
                var result = !(String.IsNullOrEmpty(Email.EmailAddress) &&
                               (FollowUpSettings.PreferredContactMethod.Equals("Email") || FollowUpSettings.ConsentToEmail));

                return(RuleResult.Assert(result, string.Format("Email required when Consenting To Email or Contact Preference is Email")));
            });

            Validator.AddRule(() => FollowUpSettings,
                              () =>
            {
                var result = !(String.IsNullOrEmpty(MobilePhone.Phone) &&
                               String.IsNullOrEmpty(HomePhone.Phone) &&
                               String.IsNullOrEmpty(WorkPhone.Phone) &&
                               (FollowUpSettings.PreferredContactMethod.Equals("Phone") || FollowUpSettings.ConsentToPhone));

                return(RuleResult.Assert(result, string.Format("Phone required when Consenting To Phone or Contact Preference is Phone")));
            });

            Validator.AddRule(() => FollowUpSettings,
                              () =>
            {
                var result = !(String.IsNullOrEmpty(StreetAddress.AddressLine1) &&
                               String.IsNullOrEmpty(StreetAddress.AddressLine2) &&
                               String.IsNullOrEmpty(StreetAddress.City) &&
                               String.IsNullOrEmpty(StreetAddress.State) &&
                               String.IsNullOrEmpty(StreetAddress.PostalCode) &&
                               (FollowUpSettings.PreferredContactMethod.Equals("Mail") || FollowUpSettings.ConsentToMail));

                return(RuleResult.Assert(result, string.Format("Street Address required when Consenting To Mail or Contact Preference is Mail")));
            });

            Validator.AddRule(() => FollowUpSettings,
                              () =>
            {
                var result = !(String.IsNullOrEmpty(MobilePhone.Phone) &&
                               (FollowUpSettings.PreferredContactMethod.Equals("Text") || FollowUpSettings.ConsentToText));

                return(RuleResult.Assert(result, string.Format("Mobile Phone required when Consenting To Text or Contact Preference is Text")));
            });

            Validator.AddRule(() => ActiveExcludeReason,
                              () =>
            {
                var result = !(FollowUpSettings.ExcludeFromFollowup && String.IsNullOrEmpty(FollowUpSettings.ExcludeReason));

                return(RuleResult.Assert(result, string.Format("Exclude Reason required")));
            });
        }
Exemplo n.º 10
0
        private void ConfigureValidationRules()
        {
            Validator.AddRule(nameof(FirstName),
                              () => RuleResult.Assert(!string.IsNullOrEmpty(FirstName) && FirstName.Length <= 25, "First Name is required and cannot be more than 25 characters"));

            Validator.AddRule(nameof(MiddleName),
                              () => RuleResult.Assert(string.IsNullOrEmpty(MiddleName) || MiddleName.Length <= 25, "Middle Name cannot be more than 25 characters"));

            Validator.AddRule(nameof(LastName),
                              () => RuleResult.Assert(!string.IsNullOrEmpty(LastName) && LastName.Length <= 25, "Last Name is required and cannot be more than 25 characters"));

            Validator.AddRule(nameof(NickName),
                              () => RuleResult.Assert(string.IsNullOrEmpty(NickName) || NickName.Length <= 40, "Alias cannot be more than 40 characters"));


            Validator.AddAsyncRule(() => Email,
                                   async() =>
            {
                var verifyViaService = (!Email.EmailVerified || (Email.EmailAddress != _originalCobuyer.Email.EmailAddress)) &&
                                       !String.IsNullOrEmpty(Email.EmailAddress);
                var result = !verifyViaService
                                           ? new EmailValidationResult()
                {
                    IsValid = true
                }
                                           : await _emailValidationService.Validate(Email);

                return(RuleResult.Assert(result.IsValid,
                                         string.Format("Valid email required" + (result.DidYouMean != null ? ". Did you mean " + result.DidYouMean : ""))));
            });

            Validator.AddAsyncRule(() => MobilePhone,
                                   async() =>
            {
                var verifyViaService = (!MobilePhone.PhoneVerified || (MobilePhone.Phone != _originalCobuyer.MobilePhoneNumber.Phone)) &&
                                       !String.IsNullOrEmpty(MobilePhone.Phone);
                var result = !verifyViaService ? true :
                             await _phoneNumberValidationService.Validate(MobilePhone);

                return(RuleResult.Assert(result,
                                         string.Format("Mobile Phone number is invalid")));
            });

            Validator.AddAsyncRule(() => HomePhone,
                                   async() =>
            {
                var verifyViaService = (!HomePhone.PhoneVerified || (HomePhone.Phone != _originalCobuyer.HomePhoneNumber.Phone)) &&
                                       !String.IsNullOrEmpty(HomePhone.Phone);
                var result = !verifyViaService ? true :
                             await _phoneNumberValidationService.Validate(HomePhone);

                return(RuleResult.Assert(result,
                                         string.Format("Home Phone number is invalid")));
            });

            Validator.AddAsyncRule(() => WorkPhone,
                                   async() =>
            {
                var verifyViaService = (!WorkPhone.PhoneVerified || (WorkPhone.Phone != _originalCobuyer.WorkPhoneNumber.Phone)) &&
                                       !String.IsNullOrEmpty(WorkPhone.Phone);
                var result = !verifyViaService ? true :
                             await _phoneNumberValidationService.Validate(WorkPhone);

                return(RuleResult.Assert(result,
                                         string.Format("Work Phone number is invalid")));
            });

            Validator.AddAsyncRule(() => StreetAddress,
                                   async() =>
            {
                var verifyViaService = (!StreetAddress.StreetAddressVerified ||
                                        (StreetAddress.AddressLine1 != _originalCobuyer.StreetAddress.AddressLine1) ||
                                        (StreetAddress.AddressLine2 != _originalCobuyer.StreetAddress.AddressLine2) ||
                                        (StreetAddress.City != _originalCobuyer.StreetAddress.City) ||
                                        (StreetAddress.State != _originalCobuyer.StreetAddress.State) ||
                                        (StreetAddress.PostalCode != _originalCobuyer.StreetAddress.PostalCode)) &&
                                       (!String.IsNullOrEmpty(StreetAddress.AddressLine1) ||
                                        !String.IsNullOrEmpty(StreetAddress.AddressLine2) ||
                                        !String.IsNullOrEmpty(StreetAddress.City) ||
                                        !String.IsNullOrEmpty(StreetAddress.State) ||
                                        !String.IsNullOrEmpty(StreetAddress.PostalCode));

                var result = !verifyViaService
                                           ? true :
                             await _streetValidationService.Validate(StreetAddress);

                return(RuleResult.Assert(result,
                                         string.Format("Street Address is invalid")));
            });


            Validator.AddRule(() => Cobuyer,
                              () =>
            {
                var result = !(String.IsNullOrEmpty(Email.EmailAddress) &&
                               String.IsNullOrEmpty(MobilePhone.Phone) &&
                               String.IsNullOrEmpty(HomePhone.Phone) &&
                               String.IsNullOrEmpty(WorkPhone.Phone) &&
                               String.IsNullOrEmpty(StreetAddress.AddressLine1) &&
                               String.IsNullOrEmpty(StreetAddress.AddressLine2) &&
                               String.IsNullOrEmpty(StreetAddress.City) &&
                               String.IsNullOrEmpty(StreetAddress.State) &&
                               String.IsNullOrEmpty(StreetAddress.PostalCode));

                return(RuleResult.Assert(result, string.Format("Enter Full Street Address or Phone Number or Email")));
            });
        }