protected void btnSave_Click(object sender, EventArgs e) { PlanMailboxViewModel viewModel = new PlanMailboxViewModel(); viewModel.ViewModelEvent += viewModel_ViewModelEvent; MailboxPlanObject obj = new MailboxPlanObject(); obj.MailboxPlanName = txtDisplayName.Text; obj.MailboxPlanDescription = txtDescription.Text; obj.MaxRecipients = int.Parse(txtMaxRecipients.Text); obj.MaxKeepDeletedItemsInDays = int.Parse(txtMaxKeepDeletedItemsInDays.Text); obj.MailboxSizeInMB = int.Parse(txtMinMailboxSize.Text); obj.MaxMailboxSizeInMB = int.Parse(txtMaxMailboxSize.Text); obj.MaxSendInKB = int.Parse(txtMaxSendSize.Text); obj.MaxReceiveInKB = int.Parse(txtMaxReceiveSize.Text); obj.EnablePOP3 = cbEnablePOP3.Checked; obj.EnableIMAP = cbEnableIMAP.Checked; obj.EnableOWA = cbEnableOWA.Checked; obj.EnableMAPI = cbEnableMAPI.Checked; obj.EnableAS = cbEnableAS.Checked; obj.EnableECP = cbEnableECP.Checked; obj.Cost = txtCostPerMailbox.Text; obj.Price = txtPricePerMailbox.Text; obj.AdditionalGBPrice = txtPricePerGB.Text; if (ddlCompanies.SelectedIndex > 0) { obj.CompanyCode = ddlCompanies.SelectedItem.Value; } else { obj.CompanyCode = string.Empty; } bool success = false; if (ddlMailboxPlans.SelectedIndex > 0) { obj.MailboxPlanID = int.Parse(ddlMailboxPlans.SelectedItem.Value); success = viewModel.UpdatePlan(obj); } else { success = viewModel.CreatePlan(obj); } if (success) { alertmessage.SetMessage(Modules.Base.Enumerations.AlertID.SUCCESS, "Successfully saved mailbox plan"); } RePopulate(); }
public bool UpdatePlan(MailboxPlanObject obj) { CPDatabase database = null; try { database = new CPDatabase(); var plan = (from p in database.Plans_ExchangeMailbox where p.MailboxPlanID == obj.MailboxPlanID select p).First(); plan.MailboxPlanName = obj.MailboxPlanName; plan.CompanyCode = obj.CompanyCode; plan.MailboxPlanDesc = obj.MailboxPlanDescription; plan.MaxRecipients = obj.MaxRecipients; plan.MaxKeepDeletedItems = obj.MaxKeepDeletedItemsInDays; plan.MailboxSizeMB = obj.MailboxSizeInMB; plan.MaxMailboxSizeMB = obj.MaxMailboxSizeInMB; plan.MaxSendKB = obj.MaxSendInKB; plan.MaxReceiveKB = obj.MaxReceiveInKB; plan.EnablePOP3 = obj.EnablePOP3; plan.EnableIMAP = obj.EnableIMAP; plan.EnableOWA = obj.EnableOWA; plan.EnableMAPI = obj.EnableMAPI; plan.EnableAS = obj.EnableAS; plan.EnableECP = obj.EnableECP; plan.Cost = obj.Cost; plan.Price = obj.Price; plan.AdditionalGBPrice = obj.AdditionalGBPrice; database.SaveChanges(); return(true); } catch (Exception ex) { this.logger.Error("Error saving mailbox plan id " + obj.MailboxPlanID, ex); ThrowEvent(AlertID.FAILED, ex.Message); return(false); } finally { if (database != null) { database.Dispose(); } } }
protected void ddlMailboxPlans_SelectedIndexChanged(object sender, EventArgs e) { if (ddlMailboxPlans.SelectedIndex > 0) { PlanMailboxViewModel viewModel = new PlanMailboxViewModel(); viewModel.ViewModelEvent += viewModel_ViewModelEvent; MailboxPlanObject obj = viewModel.GetPlan(int.Parse(ddlMailboxPlans.SelectedItem.Value)); if (obj != null && obj.MailboxPlanID > 0) { ListItem item = ddlCompanies.Items.FindByValue(obj.CompanyCode); if (item != null) { ddlCompanies.SelectedValue = item.Value; } else { ddlCompanies.SelectedIndex = 0; } txtDisplayName.Text = obj.MailboxPlanName; txtDescription.Text = obj.MailboxPlanDescription; txtMaxRecipients.Text = obj.MaxRecipients.ToString(); txtMaxKeepDeletedItemsInDays.Text = obj.MaxKeepDeletedItemsInDays.ToString(); txtMinMailboxSize.Text = obj.MailboxSizeInMB.ToString(); txtMaxMailboxSize.Text = obj.MaxMailboxSizeInMB.ToString(); txtMaxSendSize.Text = obj.MaxSendInKB.ToString(); txtMaxReceiveSize.Text = obj.MaxReceiveInKB.ToString(); cbEnablePOP3.Checked = obj.EnablePOP3; cbEnableIMAP.Checked = obj.EnableIMAP; cbEnableOWA.Checked = obj.EnableOWA; cbEnableMAPI.Checked = obj.EnableMAPI; cbEnableAS.Checked = obj.EnableAS; cbEnableECP.Checked = obj.EnableECP; txtCostPerMailbox.Text = obj.Cost; txtPricePerMailbox.Text = obj.Price; txtPricePerGB.Text = obj.AdditionalGBPrice; } else { alertmessage.SetMessage(Modules.Base.Enumerations.AlertID.FAILED, "Unable to find plan"); } } else { RePopulate(); } }
public Response GetMailboxPlan(string id) { MailboxPlanObject test = new MailboxPlanObject(); test.MailboxPlanName = "Bronze"; test.MailboxPlanDescription = "Bronze package includes everything but Activesync"; test.MaxRecipients = 100; test.MaxKeepDeletedItemsInDays = 15; test.MailboxSizeInMB = 2048; test.MaxMailboxSizeInMB = 4096; test.MaxSendInKB = 25600; test.MaxReceiveInKB = 25600; test.EnablePOP3 = true; test.EnableIMAP = true; test.EnableOWA = true; test.EnableMAPI = true; test.EnableAS = false; test.EnableECP = true; test.Cost = "1.95"; test.Price = "3.95"; test.AdditionalGBPrice = "1.00"; return(Response.AsJson(test, HttpStatusCode.OK)); }
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; }
public void CreateMailbox(UsersObject user) { CPDatabase database = null; ExchangePowershell powershell = null; CloudPanelTransaction transaction = new CloudPanelTransaction(); try { database = new CPDatabase(); // Get the user from the database var foundUser = (from u in database.Users where u.UserPrincipalName == user.UserPrincipalName select u).FirstOrDefault(); powershell = new ExchangePowershell(StaticSettings.ExchangeURI, StaticSettings.Username, StaticSettings.DecryptedPassword, StaticSettings.ExchangeUseKerberos, StaticSettings.PrimaryDC); // Get the selected mailbox plan MailboxPlanObject mailboxPlan = GetMailboxPlan(user.MailboxPlan); // Create new mailbox and register transaction powershell.NewMailbox(user); transaction.NewMailbox(user.UserPrincipalName); // Update the mailbox values powershell.UpdateMailbox(user, mailboxPlan); powershell.UpdateCASMailbox(user, mailboxPlan); // Set litigation hold settings if enabled for litigation hold if (user.LitigationHoldEnabled) { powershell.NewLitigationHold(user.UserPrincipalName, user.LitigationHoldComment, user.LitigationHoldUrl, user.LitigationHoldDuration); } // Set archive settings if enabled for archiving if (user.ArchivingEnabled && user.ArchivePlan > 0) { powershell.NewArchiveMailbox(user); // Set quota on archive } foundUser.Email = user.PrimarySmtpAddress; foundUser.MailboxPlan = user.MailboxPlan; foundUser.AdditionalMB = user.SetMailboxSizeInMB - mailboxPlan.MailboxSizeInMB; foundUser.ExchArchivePlan = user.ArchivePlan; database.SaveChanges(); } catch (Exception ex) { this.logger.Error("Error creating mailbox for " + user.UserPrincipalName, ex); ThrowEvent(AlertID.FAILED, ex.Message); transaction.RollBack(); } finally { if (powershell != null) { powershell.Dispose(); } if (database != null) { database.Dispose(); } } }