示例#1
0
        void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (chkChangePasswordQuestionAnswer.IsChecked == true &&
                (string.IsNullOrEmpty(txtPasswordQuestion.Text) || string.IsNullOrEmpty(txtPasswordAnswer.Text)))
            {
                MessageBox.Show(ResourceHelper.GetReourceValue("UserAccount_QuestionPasswordEmpty"), ResourceHelper.GetReourceValue("Common_ValidationError"), MessageBoxButton.OK);
                return;
            }

            if (uiUsers.SelectedValue != null && (Guid)uiUsers.SelectedValue != Guid.Empty)//Means update user
            {
                Guid    userId  = (Guid)uiUsers.SelectedValue;
                AspUser aspUser = _aspUsers.FirstOrDefault(i => i.UserId == userId);
                if (aspUser != null)
                {
                    Globals.IsBusy = true;
                    aspUser        = GetSaveAspUser(aspUser);
                    DataServiceHelper.SaveAspUserAsync(aspUser, SaveAspUserCompleted);
                }
                if (chkChangePasswordQuestionAnswer.IsChecked == true &&
                    string.IsNullOrEmpty(txtInputPassword.Password))
                {
                    MessageBox.Show(ResourceHelper.GetReourceValue("UserAccount_.InputPasswordEmpty"), ResourceHelper.GetReourceValue("Common_ValidationError"), MessageBoxButton.OK);
                    return;
                }
            }
            else//means create new user
            {
                if (string.IsNullOrEmpty(uiUsers.Text) || string.IsNullOrEmpty(txtPassword.Password))
                {
                    MessageBox.Show(ResourceHelper.GetReourceValue("UserAccount_.UserPasswordEmpty"), ResourceHelper.GetReourceValue("Common_ValidationError"), MessageBoxButton.OK);
                    return;
                }
                AspUser newUser = new AspUser();
                newUser.OrganisationId = Globals.UserLogin.UserOrganisationId;
                newUser.UserName       = uiUsers.Text;
                newUser.Password       = txtPassword.Password;
                newUser = GetSaveAspUser(newUser);
                if (_currentOrgId > 0)
                {
                    newUser.OrganisationId = _currentOrgId;
                }
                if (string.IsNullOrEmpty(newUser.PasswordQuestion))
                {
                    newUser.PasswordQuestion = ResourceHelper.GetReourceValue("UserAccount_DefaultPasswordQuestion");
                }
                if (string.IsNullOrEmpty(newUser.PasswordAnswer))
                {
                    newUser.PasswordAnswer = ResourceHelper.GetReourceValue("UserAccount_DefaultPasswordAnswer");
                }
                Globals.IsBusy = true;
                DataServiceHelper.SaveAspUserAsync(newUser, CreateAspUserCompleted);
            }
        }