public override void Merge(IValidationDictionary vd)
 {
     foreach (var err in vd.ErrorDictionary)
     {
         AddError(err.PropertyName, err.Message);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Check that user data is valid.
        /// </summary>
        /// <param name="user">User to validate</param>
        /// <param name="validationDictionary">Dictionary of errors</param>
        /// <returns></returns>
        public bool ValidateUser(User user, IValidationDictionary validationDictionary)
        {
            // Email cannot be null
            if (string.IsNullOrEmpty(user.Email))
            {
                validationDictionary.AddError("Email", "Email is required.");
            }
            else if (!EmailValidator.IsValid(user.Email))
            {
                validationDictionary.AddError("Email", "Invalid email address.");
            }
            else
            {
                // Check for existing email
                var existing = GetUserByEmail(user.Email);
                if (existing != null && existing.Id != user.Id)
                {
                    validationDictionary.AddError("Email", "Email is already in use. Please try another");
                }
            }

            if (user.HashedPassword == null || user.HashedPassword.Length == 0)
            {
                validationDictionary.AddError("Password", "Password is required.");
            }
            return(validationDictionary.IsValid);
        }
 public override void Merge(IValidationDictionary vd)
 {
     foreach (var err in vd.ErrorDictionary)
     {
         AddError(err.PropertyName, err.Message);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Validate resource information is valid to save
        /// </summary>
        /// <param name="resource">Resource to validate</param>
        /// <param name="validationDictionary">Validation error dictionary</param>
        /// <returns>If resource is valid</returns>
        public bool ValidateResource(Resource resource, IValidationDictionary validationDictionary)
        {
            if (String.IsNullOrEmpty(resource.Name))
            {
                validationDictionary.AddError("Name", "Resource name is required.");
            }

            return(validationDictionary.IsValid);
        }
 /// <summary>
 /// Validate form-level request
 /// </summary>
 /// <param name="validationDictionary"></param>
 public bool ValidateRequest(IValidationDictionary validationDictionary)
 {
     var requestDictionary = new ValidationDictionary();
     if (Password != ConfirmPassword)
     {
         requestDictionary.AddError("Password", "Passwords do not match.");
     }
     validationDictionary.Merge(requestDictionary);
     return requestDictionary.IsValid;
 }
 /// <summary>
 /// Validate form-level request
 /// </summary>
 /// <param name="validationDictionary"></param>
 public bool ValidateRequest(IValidationDictionary validationDictionary)
 {
     var requestDictionary = new ValidationDictionary();
     if (string.IsNullOrEmpty(ResetToken))
     {
         requestDictionary.AddError("ResetToken", "Reset token not specified.");
     }
     if (string.IsNullOrEmpty(Password))
     {
         requestDictionary.AddError("Password", "Password is required.");
     }
     if (Password != ConfirmPassword)
     {
         requestDictionary.AddError("Password", "Passwords do not match.");
     }
     validationDictionary.Merge(requestDictionary);
     return requestDictionary.IsValid;
 }
Beispiel #7
0
 public abstract void Merge(IValidationDictionary validationDictionary);
 public abstract void Merge(IValidationDictionary validationDictionary);
        /// <summary>
        /// Validate resource information is valid to save
        /// </summary>
        /// <param name="resource">Resource to validate</param>
        /// <param name="validationDictionary">Validation error dictionary</param>
        /// <returns>If resource is valid</returns>
        public bool ValidateResource(Resource resource, IValidationDictionary validationDictionary)
        {
            if (String.IsNullOrEmpty(resource.Name))
                validationDictionary.AddError("Name", "Resource name is required.");

            return validationDictionary.IsValid;
        }
        /// <summary>
        /// Check that user data is valid.
        /// </summary>
        /// <param name="user">User to validate</param>
        /// <param name="validationDictionary">Dictionary of errors</param>
        /// <returns></returns>
        public bool ValidateUser(User user, IValidationDictionary validationDictionary)
        {
            // Email cannot be null
            if (string.IsNullOrEmpty(user.Email))
            {
                validationDictionary.AddError("Email", "Email is required.");
            } else if (!EmailValidator.IsValid(user.Email))
            {
                validationDictionary.AddError("Email", "Invalid email address.");
            } else {
                // Check for existing email
                var existing = GetUserByEmail(user.Email);
                if (existing != null && existing.Id != user.Id)
                {
                    validationDictionary.AddError("Email", "Email is already in use. Please try another");
                }
            }

            if (user.HashedPassword == null || user.HashedPassword.Length == 0)
            {
                validationDictionary.AddError("Password", "Password is required.");
            }
            return validationDictionary.IsValid;
        }