public void Create(CompanyPlanObject plan) { CPDatabase database = null; try { database = new CPDatabase(); Plans_Organization newPlan = new Plans_Organization(); newPlan.OrgPlanName = plan.CompanyPlanName; newPlan.MaxUsers = plan.MaxUser; newPlan.MaxDomains = plan.MaxDomains; newPlan.MaxExchangeMailboxes = plan.MaxExchangeMailboxes; newPlan.MaxExchangeContacts = plan.MaxExchangeContacts; newPlan.MaxExchangeDistLists = plan.MaxExchangeDistributionGroups; newPlan.MaxExchangeResourceMailboxes = plan.MaxExchangeResourceMailboxes; newPlan.MaxExchangeMailPublicFolders = plan.MaxExchangeMailPublicFolders; database.Plans_Organization.Add(newPlan); database.SaveChanges(); } catch (Exception ex) { this.logger.Error("Error saving new company plan " + plan.CompanyPlanName + " to the database.", ex); ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message); } finally { if (database != null) database.Dispose(); } }
public void Update(CompanyPlanObject plan) { CPDatabase database = null; try { database = new CPDatabase(); var findPlan = (from p in database.Plans_Organization where p.OrgPlanID == plan.CompanyPlanID select p).FirstOrDefault(); findPlan.OrgPlanName = plan.CompanyPlanName; findPlan.MaxUsers = plan.MaxUser; findPlan.MaxDomains = plan.MaxDomains; findPlan.MaxExchangeMailboxes = plan.MaxExchangeMailboxes; findPlan.MaxExchangeContacts = plan.MaxExchangeContacts; findPlan.MaxExchangeDistLists = plan.MaxExchangeDistributionGroups; findPlan.MaxExchangeMailboxes = plan.MaxExchangeMailboxes; findPlan.MaxExchangeMailPublicFolders = plan.MaxExchangeMailPublicFolders; database.SaveChanges(); } catch (Exception ex) { this.logger.Error("Error updating company plan " + plan.CompanyPlanName + " with id " + plan.CompanyPlanID, ex); ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message); } finally { if (database != null) database.Dispose(); } }
private void UpdatePlan(int? planID) { CompanyPlanObject newPlan = new CompanyPlanObject(); newPlan.CompanyPlanName = txtDisplayName.Text; int maxUsers = 1; int.TryParse(txtMaxUsers.Text, out maxUsers); newPlan.MaxUser = maxUsers; int maxDomains = 1; int.TryParse(txtMaxDomains.Text, out maxDomains); newPlan.MaxDomains = maxDomains; int maxMailboxes = 0; int.TryParse(txtMaxMailboxes.Text, out maxMailboxes); newPlan.MaxExchangeMailboxes = maxMailboxes; int maxContacts = 0; int.TryParse(txtMaxContacts.Text, out maxContacts); newPlan.MaxExchangeContacts = maxContacts; int maxGroups = 0; int.TryParse(txtMaxGroups.Text, out maxGroups); newPlan.MaxExchangeDistributionGroups = maxGroups; int maxResourceMailboxes = 0; int.TryParse(txtMaxResourceMailboxes.Text, out maxResourceMailboxes); newPlan.MaxExchangeResourceMailboxes = maxResourceMailboxes; int maxEmailPublicFolders = 0; int.TryParse(txtMaxMailPublicFolders.Text, out maxEmailPublicFolders); newPlan.MaxExchangeMailPublicFolders = maxEmailPublicFolders; // Update or Create PlanCompanyViewModel viewModel = new PlanCompanyViewModel(); viewModel.ViewModelEvent += viewModel_ViewModelEvent; if (planID == null) { viewModel.Create(newPlan); } else { newPlan.CompanyPlanID = (int)planID; viewModel.Update(newPlan); } // Refresh GetAllPlans(); }