public bool CreatePlan(MailboxPlanObject obj) { CPDatabase database = null; try { database = new CPDatabase(); Plans_ExchangeMailbox plan = new Plans_ExchangeMailbox(); 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.Plans_ExchangeMailbox.Add(plan); database.SaveChanges(); return true; } catch (Exception ex) { this.logger.Error("Error creating new mailbox plan", ex); ThrowEvent(AlertID.FAILED, ex.Message); return false; } finally { if (database != null) database.Dispose(); } }
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 void UpdateMailbox(UsersObject user, MailboxPlanObject mailboxPlan) { try { this.logger.Debug("Updating mailbox for " + user.UserPrincipalName); PSCommand cmd = new PSCommand(); cmd.AddCommand("Set-Mailbox"); cmd.AddParameter("Identity", user.UserPrincipalName); cmd.AddParameter("CustomAttribute1", user.CompanyCode); cmd.AddParameter("DeliverToMailboxAndForward", user.DeliverToMailboxAndForward); cmd.AddParameter("HiddenFromAddressListsEnabled", user.MailboxHiddenFromGAL); cmd.AddParameter("IssueWarningQuota", mailboxPlan.WarningSizeInMB(user.SetMailboxSizeInMB)); cmd.AddParameter("ProhibitSendQuota", user.SetMailboxSizeInMB + "MB"); cmd.AddParameter("ProhibitSendReceiveQuota", user.SetMailboxSizeInMB + "MB"); cmd.AddParameter("MaxReceiveSize", mailboxPlan.MaxReceiveInKB + "KB"); cmd.AddParameter("MaxSendSize", mailboxPlan.MaxSendInKB + "KB"); cmd.AddParameter("RecipientLimits", mailboxPlan.MaxRecipients); cmd.AddParameter("RetainDeletedItemsFor", mailboxPlan.MaxKeepDeletedItemsInDays); cmd.AddParameter("RetainDeletedItemsUntilBackup", true); cmd.AddParameter("UseDatabaseQuotaDefaults", false); cmd.AddParameter("OfflineAddressBook", user.CompanyCode + " OAL"); List<string> emailAddresses = new List<string>(); emailAddresses.Add("SMTP:" + user.PrimarySmtpAddress); foreach (string e in user.EmailAliases) { if (e.StartsWith("sip:", StringComparison.CurrentCultureIgnoreCase)) emailAddresses.Add(e); else if (e.StartsWith("x500:", StringComparison.CurrentCultureIgnoreCase)) emailAddresses.Add(e); else if (e.StartsWith("x400:", StringComparison.CurrentCultureIgnoreCase)) emailAddresses.Add(e); else emailAddresses.Add("smtp:" + e); } cmd.AddParameter("EmailAddresses", emailAddresses.ToArray()); if (!string.IsNullOrEmpty(user.ForwardingTo)) cmd.AddParameter("ForwardingAddress", user.ForwardingTo); if (!string.IsNullOrEmpty(user.ThrottlingPolicy)) cmd.AddParameter("ThrottlingPolicy", user.ThrottlingPolicy); cmd.AddParameter("Confirm", false); cmd.AddParameter("DomainController", domainController); powershell.Commands = cmd; Collection<PSObject> obj = powershell.Invoke(); if (powershell.HadErrors) throw powershell.Streams.Error[0].Exception; } catch (Exception ex) { this.logger.Error("Failed to update mailbox for " + user.UserPrincipalName, ex); throw; } }
public void UpdateCASMailbox(UsersObject user, MailboxPlanObject mailboxPlan) { try { this.logger.Debug("Updating CAS mailbox for " + user.UserPrincipalName); PSCommand cmd = new PSCommand(); cmd.AddCommand("Set-CASMailbox"); cmd.AddParameter("Identity", user.UserPrincipalName); cmd.AddParameter("ActiveSyncEnabled", mailboxPlan.EnableAS); cmd.AddParameter("ECPEnabled", mailboxPlan.EnableECP); cmd.AddParameter("ImapEnabled", mailboxPlan.EnableIMAP); cmd.AddParameter("MAPIEnabled", mailboxPlan.EnableMAPI); cmd.AddParameter("OWAEnabled", mailboxPlan.EnableOWA); cmd.AddParameter("PopEnabled", mailboxPlan.EnablePOP3); // Email Addresses if (!string.IsNullOrEmpty(user.ActiveSyncName)) cmd.AddParameter("ActiveSyncMailboxPolicy", user.ActiveSyncName); else cmd.AddParameter("ActiveSyncMailboxPolicy", null); cmd.AddParameter("Confirm", false); cmd.AddParameter("DomainController", domainController); powershell.Commands = cmd; Collection<PSObject> obj = powershell.Invoke(); if (powershell.HadErrors) throw powershell.Streams.Error[0].Exception; } catch (Exception ex) { this.logger.Error("Failed to set CAS mailbox for " + user.UserPrincipalName, ex); throw; } }
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); }