public gvar fillgvar(string value, string control)
        {
            //Fills the Gvar and returns.
            gvar returnValue = new gvar();

            returnValue.Value   = value;
            returnValue.Control = control;
            returnValue.Success = false;
            return(returnValue);
        }
        public gvar Required(string value, string control)
        {
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            string error = "This field is required.";

            if (!string.IsNullOrEmpty(returnValue.Value.ToString()))
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar Datetime(string value, string control)
        {
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            string   error = "This field requires a date time in the format mm/dd/yyyy.";
            DateTime testValue;

            if (DateTime.TryParse(returnValue.Value.ToString(), out testValue))
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar Decimal(string value, string control)
        {
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            string  error = "This field requires a number only.";
            decimal testValue;

            if (decimal.TryParse(returnValue.Value.ToString(), out testValue))
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar Bool(string value, string control)
        {
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            string error = "This field requires a true or false only.";
            bool   testValue;

            if (Boolean.TryParse(returnValue.Value.ToString(), out testValue))
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar Special(string value, string control)
        {
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            bool   testBool = Regex.IsMatch(returnValue.Value.ToString(), "^[a-zA-Z]+$");
            string error    = "This field requires only letters";

            if (testBool == true)
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar Compare(string value, string control, string compareValue)
        {
            //compareValue: The item to compare to
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            string error = "The two values do not match";

            if (returnValue.Value.ToString() == compareValue)
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar RangeInt(string value, string control, int smallValue, int bigValue)
        {
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            int    val   = int.Parse(returnValue.Value.ToString());
            string error = string.Format("This field does not meet the range contraints. Must be between {0} and {1}.", smallValue, bigValue);

            if (val >= smallValue && val <= bigValue)
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar PasswordCompare(string value, string control, string compareValue)
        {
            //compareValue: The item to compare to
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            string error = "The password and the confirmation do no match.";

            if (returnValue.Value.ToString() == compareValue)
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar PasswordCharacters(string value, string control)
        {
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            Regex  regexPassword = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}");
            bool   testBool      = regexPassword.IsMatch(returnValue.Value.ToString());
            string error         = "Password must contain: Minimum 8 characters atleast 1 UpperCase Alphabet, 1 LowerCase Alphabet, 1 Number and 1 Special Character";

            if (testBool == true)
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar Lenght(string value, string control, int lenght, int type)
        {
            //type:
            //1: greater
            //2: Less
            //3: exatly
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            string error = "";
            string val   = returnValue.Value.ToString();

            if (type == 1)
            {
                error = string.Format("This field does not meet the lenght contraints. Must be at least {0} characters long.", lenght);
                if (val.Length >= lenght)
                {
                    returnValue.Success = true;
                }
            }
            if (type == 2)
            {
                error = string.Format("This field does not meet the lenght contraints. Must be no more than {0} characters long.", lenght);
                if (val.Length <= lenght)
                {
                    returnValue.Success = true;
                }
            }
            if (type == 3)
            {
                error = string.Format("This field does not meet the lenght contraints. Must be exactly {0} characters long.", lenght);
                if (val.Length == lenght)
                {
                    returnValue.Success = true;
                }
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar Email(string value, string control)
        {
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);
            Regex regexEmail = new Regex(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");

            bool   testBool = regexEmail.IsMatch(returnValue.Value.ToString());
            string error    = "Emails must match: [email protected]";

            if (testBool == true)
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar Phone(string value, string control)
        {
            gvar returnValue = new gvar();

            returnValue = fillgvar(value, control);

            Regex  regexPhoneNumber = new Regex(@"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$");
            bool   testBool         = regexPhoneNumber.IsMatch(returnValue.Value.ToString());
            string error            = "Phone Numbers must match: (123) 123-1234";

            if (testBool == true)
            {
                returnValue.Success = true;
            }
            if (returnValue.Success == false)
            {
                returnValue.Message = error;
            }
            return(returnValue);
        }
        public gvar AddNewUser(User newuser)
        {
            gvar returnValue = new gvar();

            try
            {
                using (var context = new BoilerContext())
                {
                    User newUser = null;
                    newUser = context.Users.Add(newuser);
                    context.SaveChanges();
                }
                returnValue.Success = true;
            }
            catch (Exception e)
            {
                returnValue.Message = e.Message.ToString();
                returnValue.Success = false;
            }
            return(returnValue);
        }
        public gvar UpdateUser(User user)
        {
            gvar returnValue = new gvar();

            try
            {
                using (var context = new BoilerContext())
                {
                    var find   = context.Users.Find(user);
                    var update = context.Entry(context.Users.Attach(find));
                    update.Property(x => x.FirstName).IsModified = true;
                    context.SaveChanges();
                }
                returnValue.Success = true;
            }
            catch (Exception e)
            {
                returnValue.Message = e.Message.ToString();
                returnValue.Success = false;
            }
            return(returnValue);
        }
    protected void btn_submit_Click(object sender, EventArgs e)
    {
        try
        {
            #region Validation
            Validator_Controller gval    = new Validator_Controller();
            List <gvar>          allVars = new List <gvar>();
            gvar intValue                  = new gvar();
            gvar boolValue                 = new gvar();
            gvar decimalValue              = new gvar();
            gvar datetimeValue             = new gvar();
            gvar rangeValue                = new gvar();
            gvar lenghtValue               = new gvar();
            gvar lettersValue              = new gvar();
            gvar phoneValue                = new gvar();
            gvar emailValue                = new gvar();
            gvar passwordValue             = new gvar();
            gvar passwordConfirmationValue = new gvar();

            string test = txt_phone.Text;

            #region txt_int
            intValue = gval.Required(txt_int.Text, "txt_int"); // Control.Text, ControlID
            allVars.Add(intValue);
            if (intValue.Success == true)
            {
                intValue = gval.Int(txt_int.Text, "txt_int");
                allVars.Add(intValue);
            }
            #endregion

            #region txt_bool
            boolValue = gval.Bool(txt_bool.Text, "txt_bool");
            allVars.Add(boolValue);
            if (boolValue.Success == true)
            {
                boolValue = gval.Bool(txt_bool.Text, "txt_bool");
                allVars.Add(boolValue);
            }
            #endregion

            #region txt_decimal
            decimalValue = gval.Decimal(txt_decimal.Text, "txt_decimal");
            allVars.Add(decimalValue);
            if (decimalValue.Success == true)
            {
                decimalValue = gval.Decimal(txt_decimal.Text, "txt_decimal");
                allVars.Add(decimalValue);
            }
            #endregion

            #region txt_datetime
            datetimeValue = gval.Datetime(txt_datetime.Text, "txt_datetime");
            allVars.Add(datetimeValue);
            if (datetimeValue.Success == true)
            {
                datetimeValue = gval.Datetime(txt_datetime.Text, "txt_datetime");
                allVars.Add(datetimeValue);
            }
            #endregion

            #region txt_range
            rangeValue = gval.Required(txt_range.Text, "txt_range");
            allVars.Add(rangeValue);
            if (rangeValue.Success == true)
            {
                rangeValue = gval.Int(txt_range.Text, "txt_range");
                allVars.Add(rangeValue);
            }
            if (rangeValue.Success == true)
            {
                rangeValue = gval.RangeInt(txt_range.Text, "txt_range", 5, 10);
                allVars.Add(rangeValue);
            }
            #endregion

            #region txt_lenght
            //This one doesn't need to check if int.
            lenghtValue = gval.Required(txt_lenght.Text, "txt_lenght");
            allVars.Add(lenghtValue);
            if (lenghtValue.Success == true)
            {
                lenghtValue = gval.Lenght(txt_lenght.Text, "txt_lenght", 5, 1);
                allVars.Add(lenghtValue);
            }
            #endregion

            #region txt_password
            //passwordValue = gval.validate(txt_password.Text, 5, "txt_password", 0, 0, "");
            //allVars.Add(passwordValue);
            //if(passwordValue.Success == true)
            //{
            //    passwordValue = gval.validate(txt_password_confrimation.Text, 5, "txt_password_confrimation", 0, 0, "");
            //    allVars.Add(passwordValue);
            //    if (passwordValue.Success == true)
            //    {
            //        passwordValue = gval.validate(txt_password.Text, 8, "txt_password", 2, 0, txt_password_confrimation.Text);
            //        allVars.Add(passwordValue);
            //    }
            //}
            #endregion

            #region txt_letters
            lettersValue = gval.Special(txt_letters.Text, "txt_letters");
            allVars.Add(lettersValue);
            if (lettersValue.Success == true)
            {
                lettersValue = gval.Special(txt_letters.Text, "txt_letters");
                allVars.Add(lettersValue);
            }
            #endregion

            #region txt_phone
            phoneValue = gval.Required(txt_phone.Text, "txt_phone");
            allVars.Add(phoneValue);
            if (phoneValue.Success == true)
            {
                phoneValue = gval.Phone(txt_phone.Text, "txt_phone");
                allVars.Add(phoneValue);
            }
            #endregion

            #region txt_email
            emailValue = gval.Email(txt_email.Text, "txt_email");
            allVars.Add(emailValue);
            if (emailValue.Success == true)
            {
                emailValue = gval.Email(txt_email.Text, "txt_email");
                allVars.Add(emailValue);
            }
            #endregion

            #region txt_password
            passwordValue = gval.Required(txt_password.Text, "txt_password");//Password required
            allVars.Add(passwordValue);

            passwordConfirmationValue = gval.Required(txt_passwordconfirmation.Text, "txt_passwordconfirmation");//Password Confirmation required
            allVars.Add(passwordConfirmationValue);

            if (passwordValue.Success == true && passwordConfirmationValue.Success == true) //Minimum 8 characters atleast 1 UpperCase Alphabet, 1 LowerCase Alphabet, 1 Number and 1 Special Character
            {
                passwordValue = gval.PasswordCharacters(txt_password.Text, "txt_password");
                allVars.Add(passwordValue);
            }
            if (passwordValue.Success == true) // Password and Confirmation match
            {
                passwordValue = gval.PasswordCompare(txt_password.Text, "txt_password", txt_passwordconfirmation.Text);
                allVars.Add(passwordValue);
            }
            #endregion

            #region Check Validation
            bool failed            = false;
            ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder");
            foreach (gvar item in allVars)
            {
                TextBox tb = (TextBox)cph.FindControl(item.Control);
                Label   lb = (Label)cph.FindControl("val_" + item.Control);
                if (item.Success == false)
                {
                    tb.CssClass = "form-control error";
                    lb.Text     = item.Message;
                    failed      = true;
                }
                else
                {
                    tb.CssClass = "form-control";
                    lb.Text     = "";
                }
            }
            #endregion
            #endregion

            if (failed != true)
            {
                int      Int      = int.Parse(intValue.Value.ToString());
                bool     Bool     = bool.Parse(boolValue.Value.ToString());
                decimal  Decimal  = decimal.Parse(decimalValue.Value.ToString());
                DateTime dateTime = DateTime.Parse(datetimeValue.Value.ToString());
                int      Range    = int.Parse(rangeValue.Value.ToString());
                string   Lenght   = lenghtValue.Value.ToString();
                //string Password = passwordValue.Value.ToString();
                string Letters = lettersValue.Value.ToString();

                lbl_int.Text      = Int.ToString();
                lbl_bool.Text     = Bool.ToString();
                lbl_decimal.Text  = Decimal.ToString();
                lbl_datetime.Text = dateTime.ToString();
                lbl_range.Text    = Range.ToString();
                lbl_lenght.Text   = Lenght.ToString();
                //lbl_password.Text = Password.ToString();
                lbl_letters.Text = Letters.ToString();

                //success call your BLL from here
                //int invalue = int.parse(intValue);
                //bool update = Controller.update(intvalue);
                //and so on.
                alerts("SUCCESS: All values match the validation.", "success");
            }
            else
            {
                alerts("ERROR: One or more values does not match the required constraints.", "error");
                //failed
            }
        }
        catch
        {
            //catch
        }
    }
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        try
        {
            #region Validation
            Validator_Controller gval    = new Validator_Controller();
            List <gvar>          allVars = new List <gvar>();
            gvar lastNameValue           = new gvar();
            gvar firstNameValue          = new gvar();
            gvar usernameValue           = new gvar();
            gvar emailValue       = new gvar();
            gvar phoneNumberValue = new gvar();
            gvar passwordValue    = new gvar();
            //gvar passwordValue = new gvar();
            gvar lettersValue = new gvar();
            #endregion

            #region check first name
            firstNameValue = gval.Required(txt_FirstName.Text, "txt_FirstName");
            allVars.Add(firstNameValue);
            if (firstNameValue.Success == true)
            {
                firstNameValue = gval.RangeString(txt_FirstName.Text, "txt_FirstName", 2, 20);
                allVars.Add(firstNameValue);
            }
            #endregion

            #region check last name
            lastNameValue = gval.Required(txt_LastName.Text, "txt_LastName");
            allVars.Add(lastNameValue);

            if (lastNameValue.Success == true)
            {
                lastNameValue = gval.RangeString(txt_LastName.Text, "txt_LastName", 2, 20);
                allVars.Add(lastNameValue);
            }
            #endregion

            #region check username
            usernameValue = gval.Required(txt_Username.Text, "txt_Username");
            allVars.Add(usernameValue);
            if (usernameValue.Success == true)
            {
                usernameValue = gval.RangeString(txt_Username.Text, "txt_Username", 2, 15);
                allVars.Add(usernameValue);
            }
            #endregion

            #region check email
            emailValue = gval.Required(txt_Email.Text, "txt_Email");
            allVars.Add(emailValue);
            if (emailValue.Success == true)
            {
                emailValue = gval.RangeString(txt_Email.Text, "txt_Email", 2, 40);
                allVars.Add(emailValue);
            }
            #endregion

            #region check phone number
            phoneNumberValue = gval.Required(txt_phone.Text, "txt_phone");
            allVars.Add(phoneNumberValue);
            if (phoneNumberValue.Success == true)
            {
                phoneNumberValue = gval.RangeString(txt_phone.Text, "txt_phone", 10, 10);
                allVars.Add(phoneNumberValue);
            }
            #endregion

            #region check password
            passwordValue = gval.Required(txt_Password.Text, "txt_Password");
            allVars.Add(passwordValue);
            if (passwordValue.Success == true)
            {
                passwordValue = gval.Int(txt_Password.Text, "txt_Password");
                allVars.Add(passwordValue);
            }
            if (passwordValue.Success == true)
            {
                passwordValue = gval.RangeString(txt_Password.Text, "txt_Password", 2, 20);
                allVars.Add(passwordValue);
            }
            #endregion

            #region Check Validation
            bool failed            = false;
            ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder");
            foreach (gvar item in allVars)
            {
                TextBox tb = (TextBox)cph.FindControl(item.Control);
                Label   lb = (Label)cph.FindControl("val_" + item.Control);
                if (item.Success == false)
                {
                    tb.CssClass = "form-control error";
                    lb.Text     = item.Message;
                    failed      = true;
                }
                else
                {
                    tb.CssClass = "form-control";
                    lb.Text     = "";
                }
            }
            #endregion

            if (failed != true)
            {
                //success call your BLL from here
                //int invalue = int.parse(intValue);
                //bool update = Controller.update(intvalue);
                //and so on.



                alerts("SUCCESS: All values match the validation.", "success");
            }
            else
            {
                alerts("ERROR: One or more values does not match the required constraints.", "error");
                //failed
            }
        }
        catch
        {
            //catch
        }
    }