internal void UpdateExchangeSection() { object userObject = ViewState["CPCurrentEditUser"]; object mailboxObject = ViewState["CPCurrentEditMailbox"]; if (userObject == null) { alertmessage.SetMessage(AlertID.FAILED, "Viewstate was null. Please contact support"); } else { UsersViewModel viewModel = new UsersViewModel(); viewModel.ViewModelEvent += viewModel_ViewModelEvent; UsersObject user = userObject as UsersObject; if (!cbEditIsMailboxEnabled.Checked && user.MailboxPlan > 0) { // // We are disabling the mailbox for this user // viewModel.DisableMailbox(user.UserPrincipalName); } else if (cbEditIsMailboxEnabled.Checked && user.MailboxPlan == 0) { // // We are creating a new mailbox // this.logger.Debug("Attempting to create new mailbox for " + user.UserPrincipalName); user = new UsersObject(); user.CompanyCode = WebSessionHandler.SelectedCompanyCode; user.UserPrincipalName = hfEditUserPrincipalName.Value; user.PrimarySmtpAddress = string.Format("{0}@{1}", txtEditMailboxEmail.Text.Replace(" ", string.Empty), ddlEditMailboxDomain.SelectedItem.Text); user.ActiveSyncPlan = ddlEditMailboxASPlan.SelectedIndex > 0 ? int.Parse(ddlEditMailboxASPlan.SelectedValue) : 0; user.MailboxPlan = int.Parse(ddlEditMailboxPlan.SelectedValue); user.SetMailboxSizeInMB = int.Parse(hfEditSelectedMailboxSize.Value); user.ForwardingTo = ddlEditMailboxForwardTo.SelectedIndex > 0 ? ddlEditMailboxForwardTo.SelectedValue : string.Empty; user.DeliverToMailboxAndForward = cbEditMailboxForwardBoth.Checked; this.logger.Debug("Validating email addresses for " + user.UserPrincipalName); user.EmailAliases = new List <string>(); if (emailAliases != null) { foreach (MailAliasObject a in emailAliases) { if (!a.Email.Equals(user.PrimarySmtpAddress)) { user.EmailAliases.Add(a.Email); } } } this.logger.Debug("Validating access permissions for " + user.UserPrincipalName); user.FullAccessUsers = new List <string>(); foreach (int i in ddlEditMailboxFullAccess.GetSelectedIndices()) { user.FullAccessUsers.Add(ddlEditMailboxFullAccess.Items[i].Value); } user.SendAsUsers = new List <string>(); foreach (int i in ddlEditMailboxSendAs.GetSelectedIndices()) { user.SendAsUsers.Add(ddlEditMailboxSendAs.Items[i].Value); } user.SendOnBehalf = new List <string>(); foreach (int i in ddlEditMailboxSendOnBehalf.GetSelectedIndices()) { user.SendOnBehalf.Add(ddlEditMailboxSendOnBehalf.Items[i].Value); } // // Archiving // this.logger.Debug("Validating archiving settings for " + user.UserPrincipalName); if (cbEditMailboxEnableArchiving.Checked) { user.ArchivingEnabled = cbEditMailboxEnableArchiving.Checked; user.ArchiveName = txtEditMailboxArchiveName.Text.Trim(); user.ArchivePlan = ddlEditMailboxArchivePlan.SelectedIndex > 0 ? int.Parse(ddlEditMailboxArchivePlan.SelectedValue) : 0; } else { user.ArchivingEnabled = false; } // // Litigation Hold // this.logger.Debug("Validating litigation hold settings for " + user.UserPrincipalName); if (cbEditMailboxEnableLitigationHold.Checked) { user.LitigationHoldEnabled = cbEditMailboxEnableLitigationHold.Checked; user.LitigationHoldUrl = txtEditMailboxLitigationHoldURL.Text; user.LitigationHoldComment = txtEditMailboxLitigationHoldComments.Text; if (!string.IsNullOrEmpty(txtEditMailboxLitigationHoldDuration.Text)) { DateTime now = DateTime.Now; DateTime end; DateTime.TryParse(txtEditMailboxLitigationHoldDuration.Text, out end); if (end != null) { TimeSpan duration = end - now; user.LitigationHoldDuration = duration.Days; } else { user.LitigationHoldDuration = 0; } } else { user.LitigationHoldDuration = 0; } } viewModel.CreateMailbox(user); } else { // // We are updating an existing mailbox // } } }