Ejemplo n.º 1
0
        internal void UpdateUserSection()
        {
            object userObject = ViewState["CPCurrentEditUser"];

            if (userObject == null)
            {
                alertmessage.SetMessage(AlertID.FAILED, "Viewstate was null. Please contact support");
            }
            else
            {
                UsersObject original = userObject as UsersObject;

                bool valuesHaveBeenUpdated = false;

                if (txtEditFirstName.Text != original.Firstname)
                {
                    valuesHaveBeenUpdated = true;
                    this.logger.Debug(string.Format("{0}: Found new value. Old Value: {0}, New Value: {1}", original.UserPrincipalName, original.Firstname, txtEditFirstName.Text));
                }

                if (txtEditMiddleName.Text != original.Middlename)
                {
                    valuesHaveBeenUpdated = true;
                    this.logger.Debug(string.Format("{0}: Found new value. Old Value: {0}, New Value: {1}", original.UserPrincipalName, original.Middlename, txtEditMiddleName.Text));
                }

                if (txtEditLastname.Text != original.Lastname)
                {
                    valuesHaveBeenUpdated = true;
                    this.logger.Debug(string.Format("{0}: Found new value. Old Value: {0}, New Value: {1}", original.UserPrincipalName, original.Lastname, txtEditLastname.Text));
                }

                if (txtEditDisplayName.Text != original.DisplayName)
                {
                    valuesHaveBeenUpdated = true;
                    this.logger.Debug(string.Format("{0}: Found new value. Old Value: {0}, New Value: {1}", original.UserPrincipalName, original.DisplayName, txtEditDisplayName.Text));
                }

                if (txtEditDepartment.Text != original.Department)
                {
                    valuesHaveBeenUpdated = true;
                    this.logger.Debug(string.Format("{0}: Found new value. Old Value: {0}, New Value: {1}", original.UserPrincipalName, original.Department, txtEditDepartment.Text));
                }

                if (cbEditEnableUser.Checked != original.IsEnabled)
                {
                    valuesHaveBeenUpdated = true;
                }

                // Only update these if reseller or super admin
                if (WebSessionHandler.IsSuperAdmin || WebSessionHandler.IsResellerAdmin)
                {
                    if (cbEditIsCompanyAdmin.Checked != original.IsCompanyAdmin)
                    {
                        valuesHaveBeenUpdated = true;
                    }

                    if (cbEditEnableExchange.Checked != original.EnableExchangePerm)
                    {
                        valuesHaveBeenUpdated = true;
                    }

                    if (cbEditDisableExchange.Checked != original.DisableExchangePerm)
                    {
                        valuesHaveBeenUpdated = true;
                    }

                    if (cbEditAddDomain.Checked != original.AddDomainPerm)
                    {
                        valuesHaveBeenUpdated = true;
                    }

                    if (cbEditDeleteDomain.Checked != original.DeleteDomainPerm)
                    {
                        valuesHaveBeenUpdated = true;
                    }

                    if (cbEditEnableAcceptedDomain.Checked != original.EnableAcceptedDomainPerm)
                    {
                        valuesHaveBeenUpdated = true;
                    }

                    if (cbEditDisableAcceptedDomain.Checked != original.DisableAcceptedDomainPerm)
                    {
                        valuesHaveBeenUpdated = true;
                    }

                    if (WebSessionHandler.IsSuperAdmin)
                    {
                        if (cbEditIsResellerAdmin.Checked != original.IsResellerAdmin)
                        {
                            valuesHaveBeenUpdated = true;
                        }
                    }
                }

                // Update user if values have changed
                if (valuesHaveBeenUpdated)
                {
                    UsersObject updateUser = new UsersObject();
                    updateUser.UserPrincipalName         = hfEditUserPrincipalName.Value;
                    updateUser.Firstname                 = txtEditFirstName.Text;
                    updateUser.Middlename                = txtEditMiddleName.Text;
                    updateUser.Lastname                  = txtEditLastname.Text;
                    updateUser.DisplayName               = txtEditDisplayName.Text;
                    updateUser.Department                = txtEditDepartment.Text;
                    updateUser.IsEnabled                 = cbEditEnableUser.Checked;
                    updateUser.IsResellerAdmin           = cbEditIsResellerAdmin.Checked;
                    updateUser.IsCompanyAdmin            = cbEditIsCompanyAdmin.Checked;
                    updateUser.EnableExchangePerm        = cbEditEnableExchange.Checked;
                    updateUser.DisableExchangePerm       = cbEditDisableExchange.Checked;
                    updateUser.AddDomainPerm             = cbEditAddDomain.Checked;
                    updateUser.DeleteDomainPerm          = cbEditDeleteDomain.Checked;
                    updateUser.EnableAcceptedDomainPerm  = cbEditEnableAcceptedDomain.Checked;
                    updateUser.DisableAcceptedDomainPerm = cbEditDisableAcceptedDomain.Checked;

                    UsersViewModel viewModel = new UsersViewModel();
                    viewModel.ViewModelEvent += viewModel_ViewModelEvent;
                    viewModel.UpdateUser(updateUser, WebSessionHandler.IsSuperAdmin || WebSessionHandler.IsResellerAdmin);
                }
            }
        }