Пример #1
0
        private void EditUser(string userPrincipalName)
        {
            UsersViewModel viewModel = new UsersViewModel();

            viewModel.ViewModelEvent += viewModel_ViewModelEvent;

            //                      //
            // GET USER INFORMATION //
            //                      //
            UsersObject user = viewModel.GetUser(userPrincipalName);

            if (user != null)
            {
                lbProfileDisplayName.Text    = user.DisplayName;
                lbProfileUsername.Text       = user.UserPrincipalName;
                lbProfileSamAccountName.Text = user.sAMAccountName;

                hfEditUserPrincipalName.Value = user.UserPrincipalName;
                txtEditFirstName.Text         = user.Firstname;
                txtEditMiddleName.Text        = user.Middlename;
                txtEditLastname.Text          = user.Lastname;
                txtEditDisplayName.Text       = user.DisplayName;
                txtEditDepartment.Text        = user.Department;

                cbEditIsCompanyAdmin.Checked  = user.IsCompanyAdmin;
                cbEditIsResellerAdmin.Checked = user.IsResellerAdmin;
                cbEditEnableUser.Checked      = user.IsEnabled;

                cbEditAddDomain.Checked             = user.AddDomainPerm;
                cbEditDeleteDomain.Checked          = user.DeleteDomainPerm;
                cbEditDisableAcceptedDomain.Checked = user.DisableAcceptedDomainPerm;
                cbEditDisableExchange.Checked       = user.DisableExchangePerm;
                cbEditEnableAcceptedDomain.Checked  = user.EnableAcceptedDomainPerm;
                cbEditEnableExchange.Checked        = user.EnableExchangePerm;

                cbEditMailboxEnableArchiving.Checked = user.ArchivePlan > 0 ? true : false;

                // Get the user photo
                imgUserPhoto.ImageUrl = string.Format("services/UserPhotoHandler.ashx?id={0}", user.UserPrincipalName);

                // Set view state
                ViewState["CPCurrentEditUser"] = user;
            }

            //                          //
            // GET MAILBOX INFORMATION  //
            //                          //
            _isExchangeEnabled = CompanyChecks.IsExchangeEnabled(WebSessionHandler.SelectedCompanyCode);
            if (_isExchangeEnabled)
            {
                // Get list of accepted domains
                PopulateEditUserView();

                // Get mailbox information
                if (user != null)
                {
                    if (user.MailboxPlan > 0)
                    {
                        cbEditIsMailboxEnabled.Checked = true;

                        MailboxPlanObject mailboxPlan = viewModel.GetMailboxPlan(user.MailboxPlan);
                        _currentMailboxSize = mailboxPlan.MailboxSizeInMB + user.AdditionalMB;

                        ListItem item = ddlEditMailboxPlan.Items.FindByValue(mailboxPlan.MailboxPlanID.ToString());
                        if (item != null)
                        {
                            ddlEditMailboxPlan.SelectedValue = item.Value;
                        }

                        UsersObject mailboxUser = viewModel.GetUserMailbox(userPrincipalName);
                        if (mailboxUser != null)
                        {
                            string[] primaryEmailAddress = mailboxUser.PrimarySmtpAddress.Split('@');

                            // Populate email information
                            txtEditMailboxEmail.Text = primaryEmailAddress[0];
                            ListItem item2 = ddlEditMailboxDomain.Items.FindByText(primaryEmailAddress[1]);
                            if (item2 != null)
                            {
                                ddlEditMailboxDomain.SelectedValue = item2.Value;
                            }

                            // Populate email aliases
                            emailAliases = new List <MailAliasObject>();
                            foreach (string s in mailboxUser.EmailAliases)
                            {
                                emailAliases.Add(new MailAliasObject()
                                {
                                    Email = s
                                });
                            }
                            ViewState["CPEmailAliases"] = emailAliases;
                            gridEmailAliases.DataSource = emailAliases;
                            gridEmailAliases.DataBind();

                            // Populate forwarding
                            if (!string.IsNullOrEmpty(mailboxUser.ForwardingTo))
                            {
                                ListItem fItem = ddlEditMailboxForwardTo.Items.FindByValue(mailboxUser.ForwardingTo);
                                if (fItem != null)
                                {
                                    ddlEditMailboxForwardTo.SelectedValue = fItem.Value;
                                }
                                else
                                {
                                    ddlEditMailboxForwardTo.SelectedIndex = -1;
                                }
                            }
                            cbEditMailboxForwardBoth.Checked = mailboxUser.DeliverToMailboxAndForward;

                            // Populate permissions
                            if (mailboxUser.FullAccessUsers != null)
                            {
                                foreach (string fullAccess in mailboxUser.FullAccessUsers)
                                {
                                    ListItem fullItem = ddlEditMailboxFullAccess.Items.FindByValue(fullAccess);
                                    if (fullItem != null)
                                    {
                                        fullItem.Selected = true;
                                    }
                                }
                            }

                            if (mailboxUser.SendAsUsers != null)
                            {
                                foreach (string sendAs in mailboxUser.SendAsUsers)
                                {
                                    ListItem sendAsItem = ddlEditMailboxSendAs.Items.FindByValue(sendAs);
                                    if (sendAsItem != null)
                                    {
                                        sendAsItem.Selected = true;
                                    }
                                }
                            }

                            if (mailboxUser.SendOnBehalf != null)
                            {
                                foreach (string sendOnBehalf in mailboxUser.SendOnBehalf)
                                {
                                    ListItem sendOnBehalfItem = ddlEditMailboxSendOnBehalf.Items.FindByValue(sendOnBehalf);
                                    if (sendOnBehalfItem != null)
                                    {
                                        sendOnBehalfItem.Selected = true;
                                    }
                                }
                            }

                            // Populate litigation hold
                            cbEditMailboxEnableLitigationHold.Checked = mailboxUser.LitigationHoldEnabled;
                            txtEditMailboxLitigationHoldURL.Text      = mailboxUser.LitigationHoldUrl;
                            txtEditMailboxLitigationHoldComments.Text = mailboxUser.LitigationHoldComment;

                            if (mailboxUser.LitigationHoldDuration > 0)
                            {
                                DateTime now = DateTime.Now.AddDays(mailboxUser.LitigationHoldDuration);
                                txtEditMailboxLitigationHoldDuration.Text = now.ToShortDateString();
                            }
                            else
                            {
                                txtEditMailboxLitigationHoldDuration.Text = string.Empty;
                            }

                            // Populate archive
                            if (user.ArchivePlan > 0)
                            {
                                txtEditMailboxArchiveName.Text = mailboxUser.ArchiveName;
                            }
                            else
                            {
                                txtEditMailboxArchiveName.Text = string.Empty;
                            }


                            ViewState["CPCurrentEditMailbox"] = mailboxUser;
                        }
                    }
                    else
                    {
                        cbEditIsMailboxEnabled.Checked = false;
                    }
                }
            }

            // Change panels
            panelCreateUser.Visible = false;
            panelUserList.Visible   = false;
            panelEditUser.Visible   = true;
        }