Exemple #1
0
 private void Password_LostFocus(object sender, RoutedEventArgs e)
 {
     if (String.IsNullOrWhiteSpace(Password.Password))
     {
         ErrorPassword.Text = "Please enter password.";
     }
     else
     {
         if (!ValidationClass.ValidatePassword(Password.Password))
         {
             ErrorPassword.Text = "Password must be within 8-20 characters";
         }
         else
         {
             ErrorPassword.Text = "";
         }
     }
 }
Exemple #2
0
        public void Validation(string name)
        {
            switch (name)
            {
            case "UserName":
                if (String.IsNullOrWhiteSpace(UserName))
                {
                    ErrorUserName = "******";
                }
                else
                {
                    ErrorUserName = "";
                    if (EditUserMode)
                    {
                        EditUser();
                    }
                }

                break;

            case "UserEmail":
                if (String.IsNullOrWhiteSpace(UserEmail))
                {
                    ErrorUserEmail = "Please enter email id";
                }
                else
                {
                    if (!ValidationClass.ValidateEmailID(UserEmail))
                    {
                        ErrorUserEmail = "Email id is not valid";
                    }
                    else
                    {
                        if (!ValidationClass.UniqueTestforEmail(UserEmail, "User") && !EditUserMode)
                        {
                            ErrorUserEmail = "This Email ID is already associated with another user";
                        }
                        else if (EditUserMode && CurrentUser != null)
                        {
                            if (!ValidationClass.UniqueTestforEmail(CurrentUser.id, UserEmail, "User"))
                            {
                                ErrorUserEmail = "This Email ID is already associated with another user";
                            }
                        }
                        else
                        {
                            ErrorUserEmail = "";
                            if (EditUserMode)
                            {
                                EditUser();
                            }
                        }
                    }
                }
                break;

            case "Password":
                if (String.IsNullOrWhiteSpace(Password))
                {
                    ErrorPassword = "******";
                }
                else
                {
                    if (!ValidationClass.ValidatePassword(Password))
                    {
                        ErrorPassword = "******";
                    }
                    else
                    {
                        ErrorPassword = "";
                    }
                }
                break;

            case "ConfirmPassword":
                if (String.IsNullOrWhiteSpace(ConfirmPassword))
                {
                    ErrorConfirmPassword = "******";
                }
                else
                {
                    if (Password != ConfirmPassword)
                    {
                        ErrorConfirmPassword = "******";
                    }
                    else
                    {
                        ErrorConfirmPassword = "";
                        if (EditUserMode)
                        {
                            EditUser();
                        }
                    }
                }
                break;

            case "Roles":
                if (CurrentUserRole == null)
                {
                    ErrorUserRole = "Please select arole for user.";
                }
                else
                {
                    ErrorUserRole = "";
                }
                break;
            }
        }
        public void Validation(string ControlName)
        {
            switch (ControlName)
            {
            case "UserName":
                if (String.IsNullOrWhiteSpace(UserName))
                {
                    ErrorUserName = "******";
                    break;
                }
                else
                {
                    ErrorUserName = "";
                }
                break;

            case "UserEmail":
                if (String.IsNullOrWhiteSpace(UserEmail))
                {
                    ErrorUserEmail = "Please enter email";
                    break;
                }
                else
                {
                    if (!ValidationClass.ValidateEmailID(UserEmail))
                    {
                        ErrorUserEmail = "This email id is not valid";
                        break;
                    }
                    else
                    {
                        using (var ctx = new Choukash_Revamp_DemoEntities())
                        {
                            var email = ctx.Users.Where(a => a.email == this.UserEmail).FirstOrDefault <User>();
                            if (email == null)
                            {
                                this.ErrorUserEmail = "";
                            }
                            else
                            {
                                this.ErrorUserEmail = "This email is alraedy associated with another user";
                            }
                        }
                        break;
                    }
                }

            case "Password":
                if (String.IsNullOrWhiteSpace(Password))
                {
                    ErrorPassword = "******";
                    break;
                }
                else
                {
                    if (!ValidationClass.ValidatePassword(Password))
                    {
                        ErrorPassword = "******";
                        break;
                    }
                    else
                    {
                        ErrorPassword = "";
                        break;
                    }
                }

            case "ConfirmPassword":
                if (String.IsNullOrWhiteSpace(ConfirmPassword))
                {
                    ErrorConfirmPassword = "******";
                    break;
                }
                else
                {
                    if (Password != ConfirmPassword)
                    {
                        ErrorConfirmPassword = "******";
                    }
                    else
                    {
                        ErrorConfirmPassword = "";
                    }

                    break;
                }
            }
        }