/// <summary>
        /// Sets the user Exchange information
        /// </summary>
        /// <param name="adUsersInfo"></param>
        private void ImportExchangeUsers(List<ADUser> adUsersInfo)
        {
            ExchCmds powershell = null;

            try
            {
                // Get the plan that was selected
                MailboxPlan selectedPlan = SQLPlans.GetMailboxPlan(int.Parse(ddlMailboxPlans.SelectedValue));

                // Get the selected mailbox size based on the slider
                int selectedSize = int.Parse(hfMailboxSizeMB.Value);
                selectedPlan.SetSizeInMB = selectedSize;

                // Calculate the additional MB that was added
                int totalAdded = selectedSize - selectedPlan.SizeInMB;

                // Initialize our powershell object
                powershell = new ExchCmds(Config.ExchangeURI, Config.Username, Config.Password, Config.ExchangeConnectionType, Config.PrimaryDC);

                // Now we need to loop through and set the mailbox information
                foreach (ADUser u in adUsersInfo)
                {
                    // Set the mailbox information
                    powershell.Set_Mailbox(u.UserPrincipalName, CPContext.SelectedCompanyCode, selectedPlan);

                    // Update SQL
                    SQLUsers.UpdateUserMailbox(u, selectedPlan);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (powershell != null)
                    powershell.Dispose();
            }
        }
예제 #2
0
        /// <summary>
        /// Saves a mailbox after it has been edited
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnEditMailboxSave_Click(object sender, EventArgs e)
        {
            ExchCmds powershell = null;

            try
            {
                // Initialize powershell
                powershell = new ExchCmds(Config.ExchangeURI, Config.Username, Config.Password, Config.ExchangeConnectionType, Config.PrimaryDC);

                // Get mailbox plan
                MailboxPlan selectedPlan = SQLPlans.GetMailboxPlan(int.Parse(ddlEditMailboxPlan.SelectedValue));

                // Initialize our collection
                MailboxUser user = new MailboxUser();
                user.UserPrincipalName = hfUserPrincipalName.Value;
                user.DistinguishedName = hfDistinguishedName.Value;
                user.PrimarySmtpAddress = string.Format("{0}@{1}", txtEditPrimaryEmail.Text.Replace(" ", string.Empty), ddlEditPrimaryEmailDomain.SelectedValue);
                user.DeliverToMailboxAndForward = cbDeliverToMailboxAndFoward.Checked;
                user.ActiveSyncMailboxPolicy = ddlActiveSyncPlanEditMailbox.SelectedIndex == 0 ? null : ddlActiveSyncPlanEditMailbox.SelectedItem.Text;

                // Get our forwrading address
                if (ddlForwardTo.SelectedIndex > 0)
                    user.ForwardingAddress = ddlForwardTo.SelectedValue;

                // Get our list of email aliases
                user.EmailAliases = new List<string>();
                if (emailAliases != null && emailAliases.Count > 0)
                {
                    foreach (BaseEmailAliases email in emailAliases)
                    {
                        user.EmailAliases.Add(email.emailAddress);
                    }
                }

                // Get the selected mailbox size based on the slider
                int selectedSize = int.Parse(hfEditMailboxSize.Value);
                int totalAdded = selectedSize - selectedPlan.SizeInMB;
                selectedPlan.SetSizeInMB = selectedSize;

                // Get the permissions and see if anything has changed or not
                GetChangedMailboxPermissions(ref user);


                //
                // Check plan features or if the plan was overridden
                //
                user.ActiveSyncEnabled = cbOverrideOptions.Checked ? cbEnableActiveSync.Checked : selectedPlan.ActiveSyncEnabled;
                user.ECPEnabled = cbOverrideOptions.Checked ? cbEnableECP.Checked : selectedPlan.ECPEnabled;
                user.IMAPEnabled = cbOverrideOptions.Checked ? cbEnableIMAP.Checked : selectedPlan.IMAPEnabled;
                user.MAPIEnabled = cbOverrideOptions.Checked ? cbEnableMAPI.Checked : selectedPlan.MAPIEnabled;
                user.OWAEnabled = cbOverrideOptions.Checked ? cbEnableOWA.Checked : selectedPlan.OWAEnabled;
                user.POP3Enabled = cbOverrideOptions.Checked ? cbEnablePOP3.Checked : selectedPlan.POP3Enabled;

                // Update the mailbox
                powershell.Set_Mailbox(user, selectedPlan);

                // Update mailbox in SQL
                SQLUsers.UpdateUserMailbox(user, selectedPlan);

                // Set notification
                notification1.SetMessage(controls.notification.MessageType.Success, Resources.LocalizedText.NotificationSuccessMailboxUpdate + user.UserPrincipalName);
            }
            catch (Exception ex)
            {
                notification1.SetMessage(controls.notification.MessageType.Error, ex.Message);
            }
            finally
            {
                if (powershell != null)
                    powershell.Dispose();

                // Revert to main screen
                GetMailboxUsers();
            }
        }