Ejemplo n.º 1
0
        public static bool ValidatePasswordMatch(this CoreViewModel model, params string[] fields)
        {
            for (int i = 0; i < fields.Length; i++)
            {
                try
                {
                    var currentPassword = fields[i];

                    // validate passwords match
                    if (i > 0)
                    {
                        var previousPassword        = fields[i - 1];
                        var previousPasswordMatches = currentPassword == previousPassword;
                        if (!previousPasswordMatches)
                        {
                            return(false);
                        }
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static bool ValidateDefaultFields <T>(this CoreViewModel model, params T[] fields) where T : struct
        {
            var state = true;
            var type  = typeof(T).Name;

            switch (type)
            {
            case "Boolean":
                foreach (var obj in fields)
                {
                    if (((bool)(object)obj) == default(bool))
                    {
                        state = false;
                    }
                }
                break;

            case "Int32":
                foreach (var obj in fields)
                {
                    if (((int)(object)obj).Equals(default(int)))
                    {
                        state = false;
                    }
                }
                break;

            case "Int64":
                foreach (var obj in fields)
                {
                    if (((long)(object)obj).Equals(default(long)))
                    {
                        state = false;
                    }
                }
                break;

            case "Double":
                foreach (var obj in fields)
                {
                    if (((double)(object)obj).Equals(default(double)))
                    {
                        state = false;
                    }
                }
                break;

            case "Single":
                foreach (var obj in fields)
                {
                    if (((float)(object)obj).Equals(default(float)))
                    {
                        state = false;
                    }
                }
                break;
            }

            return(state);
        }
Ejemplo n.º 3
0
 public static bool ValidateDateFields(this CoreViewModel model, DateTime minValue, DateTime maxValue, params DateTime[] fields)
 {
     foreach (var obj in fields)
     {
         if (obj < minValue || obj > maxValue)
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 4
0
 public static bool ValidateNumberFields(this CoreViewModel model, decimal minValue, decimal maxValue, params decimal[] fields)
 {
     foreach (var obj in fields)
     {
         if (obj < minValue || obj > maxValue)
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 5
0
        public static bool ValidateTextFields(this CoreViewModel model, params string[] fields)
        {
            foreach (var obj in fields)
            {
                if (String.IsNullOrEmpty(obj))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
        public static bool ValidateEmailFields(this CoreViewModel model, params string[] fields)
        {
            var RegexExp = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";

            foreach (var obj in fields)
            {
                try
                {
                    return(Regex.IsMatch(obj, RegexExp, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(false);
        }
Ejemplo n.º 7
0
        public static bool ValidatePasswordFields(this CoreViewModel model, params string[] fields)
        {
            var hasNumber = new Regex(@"[0-9]+");
            var hasChar   = new Regex(@"[a-zA-Z]+");
            //var hasCorrectNumChars = new Regex(@"^.{8,16}$");
            var hasCorrectNumChars = new Regex(@"^.{8,}$");

            foreach (var obj in fields)
            {
                try
                {
                    return(hasNumber.IsMatch(obj) && hasChar.IsMatch(obj) && hasCorrectNumChars.IsMatch(obj));
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(false);
        }