public CompanyModule(CloudPanelContext db) : base("Company") { this.RequiresAuthentication(); this.RequiresAnyClaim(new[] { "SuperAdmin", "ResellerAdmin", "CompanyAdmin" }); Get["{CompanyCode}"] = parameters => { string companyCode = parameters.CompanyCode; var user = this.Context.CurrentUser as AuthenticatedUser; user.SelectedCompanyCode = companyCode; // Get company information var companyData = (from c in db.Companies where !c.IsReseller where c.CompanyCode == companyCode select new CompanyObject() { CompanyCode = companyCode, CompanyName = c.CompanyName, AdminName = c.AdminName, Telephone = c.PhoneNumber, CompanyPlanID = c.OrgPlanID == null ? 0 : (int)c.OrgPlanID }).FirstOrDefault(); user.SelectedCompanyName = companyData.CompanyName; return(View["Company/Overview", companyData]); }; }
public CompanyModule(CloudPanelContext db) : base("Company") { this.RequiresAuthentication(); this.RequiresAnyClaim(new[] { "SuperAdmin", "ResellerAdmin", "CompanyAdmin" }); Get["{CompanyCode}"] = parameters => { string companyCode = parameters.CompanyCode; var user = this.Context.CurrentUser as AuthenticatedUser; user.SelectedCompanyCode = companyCode; // Get company information var companyData = (from c in db.Companies where !c.IsReseller where c.CompanyCode == companyCode select new CompanyObject() { CompanyCode = companyCode, CompanyName = c.CompanyName, AdminName = c.AdminName, Telephone = c.PhoneNumber, CompanyPlanID = c.OrgPlanID == null ? 0 : (int)c.OrgPlanID }).FirstOrDefault(); user.SelectedCompanyName = companyData.CompanyName; return View["Company/Overview", companyData]; }; }
public static string FindAvailableCompanyCode(string companyName, CloudPanelContext db) { char[] charArray = companyName.ToCharArray(); charArray = Array.FindAll<char>(charArray, (c => (char.IsLetterOrDigit(c)))); string companyCode = new string(charArray); if (companyCode.Length < 3) throw new FormatException(companyCode); else { companyCode = companyCode.Substring(0, 3); int increment = 1; string newCompanyCode = companyCode; bool foundGoodCode = false; do { var found = (from c in db.Companies where c.CompanyCode.Equals(newCompanyCode, StringComparison.CurrentCultureIgnoreCase) select c).Count(); if (found > 0) { newCompanyCode = string.Format("{0}{1}", companyCode, increment); increment = increment + 1; } else foundGoodCode = true; } while (!foundGoodCode); return newCompanyCode.ToUpper(); } }
public ajaxSuper(CloudPanelContext db) : base("/AJAX") { //this.RequiresAuthentication(); //this.RequiresAnyClaim(new[] { "SuperAdmin" }); Get["/Resellers/GetAll"] = parameters => GetResellers(); Get["/Dashboard/Charting/Column"] = parameters => GetTop5Customers(); }
public ajaxReseller(CloudPanelContext db) : base("/AJAX") { this.db = db; //this.RequiresAuthentication(); //this.RequiresAnyClaim(new[] { "SuperAdmin", "ResellerAdmin" }); Get["/Resellers/{ResellerCode}/Companies/GetAll"] = parameters => GetCompanies(parameters.ResellerCode); }
public ajaxSuper(CloudPanelContext db) : base("/AJAX") { //this.RequiresAuthentication(); //this.RequiresAnyClaim(new[] { "SuperAdmin" }); Get["/Resellers/GetAll"] = parameters => GetResellers(); Get["/Dashboard/Charting/Column"] = parameters => GetTop5Customers(); }
public ajaxAll(CloudPanelContext db) : base("/AJAX") { this.db = db; //this.RequiresAuthentication(); Get["/Plans/Company/Get/{ID}"] = parameters => GetCompanyPlan(parameters.ID); Get["/Plans/Mailbox/Get/{ID}"] = parameters => GetMailboxPlan(parameters.ID); Get["/Company/Charting/Column/{CompanyCode}"] = parameters => GetCompanyColumnChart(parameters.CompanyCode); Get["/Company/{CompanyCode}/Users/GetAll"] = parameters => GetUsers(parameters.CompanyCode); }
public ajaxReseller(CloudPanelContext db) : base("/AJAX") { this.db = db; //this.RequiresAuthentication(); //this.RequiresAnyClaim(new[] { "SuperAdmin", "ResellerAdmin" }); Get["/Resellers/{ResellerCode}/Companies/GetAll"] = parameters => GetCompanies(parameters.ResellerCode); }
public ajaxAll(CloudPanelContext db) : base("/AJAX") { this.db = db; //this.RequiresAuthentication(); Get["/Plans/Company/Get/{ID}"] = parameters => GetCompanyPlan(parameters.ID); Get["/Plans/Mailbox/Get/{ID}"] = parameters => GetMailboxPlan(parameters.ID); Get["/Company/Charting/Column/{CompanyCode}"] = parameters => GetCompanyColumnChart(parameters.CompanyCode); Get["/Company/{CompanyCode}/Users/GetAll"] = parameters => GetUsers(parameters.CompanyCode); }
public EmailModule(CloudPanelContext db) : base("Company") { //this.RequiresAuthentication(); //this.RequiresAnyClaim(new[] { "SuperAdmin", "ResellerAdmin", "CompanyAdmin" }); Get["{CompanyCode}/Email/Status"] = parameters => { try { string companyCode = parameters.CompanyCode; var company = (from c in db.Companies where !c.IsReseller where c.CompanyCode == companyCode select c).FirstOrDefault(); if (company.ExchEnabled) { var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random(); var result = new string( Enumerable.Repeat(chars, 8) .Select(s => s[random.Next(s.Length)]) .ToArray()); return View["Company/Email/Disable.cshtml", result]; } else { return View["Company/Email/Enable.cshtml"]; } } catch (Exception ex) { log.Error("Error checking Exchange status for " + parameters.CompanyCode, ex); return View["Company/Overview.cshtml"]; } }; Post["{CompanyCode}/Email/Enable"] = parameters => { // If successful take them to the disable Exchange page // If they are NOT successful take them back to the enable Exchange page and display an error message why it wasn't successful return Response.AsRedirect("Status"); }; Post["{CompanyCode}/Email/Disable"] = parameters => { // If we successfully disable email then redirect to enable page // Otherwise redirect to same page displaying the error message return Response.AsRedirect("Status"); }; }
public EmailModule(CloudPanelContext db) : base("Company") { //this.RequiresAuthentication(); //this.RequiresAnyClaim(new[] { "SuperAdmin", "ResellerAdmin", "CompanyAdmin" }); Get["{CompanyCode}/Email/Status"] = parameters => { try { string companyCode = parameters.CompanyCode; var company = (from c in db.Companies where !c.IsReseller where c.CompanyCode == companyCode select c).FirstOrDefault(); if (company.ExchEnabled) { var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random(); var result = new string( Enumerable.Repeat(chars, 8) .Select(s => s[random.Next(s.Length)]) .ToArray()); return(View["Company/Email/Disable.cshtml", result]); } else { return(View["Company/Email/Enable.cshtml"]); } } catch (Exception ex) { log.Error("Error checking Exchange status for " + parameters.CompanyCode, ex); return(View["Company/Overview.cshtml"]); } }; Post["{CompanyCode}/Email/Enable"] = parameters => { // If successful take them to the disable Exchange page // If they are NOT successful take them back to the enable Exchange page and display an error message why it wasn't successful return(Response.AsRedirect("Status")); }; Post["{CompanyCode}/Email/Disable"] = parameters => { // If we successfully disable email then redirect to enable page // Otherwise redirect to same page displaying the error message return(Response.AsRedirect("Status")); }; }
public static IHtmlString GetEmailDomains(string companyCode) { var sb = new StringBuilder(); CloudPanelContext db = null; try { db = new CloudPanelContext(Settings.ConnectionString); var domains = from d in db.Domains where d.CompanyCode == companyCode orderby d.Domain1 select d; foreach (var d in domains) { sb.AppendFormat("<option value='{0}' {1}>{2}</option>", d.DomainID, d.IsDefault ? "selected" : "", d.Domain1); } } catch (Exception ex) { sb.AppendFormat("<option value='0' selected>{1}: {2}</option>", "ERROR", ex.Message); log.ErrorFormat("Error getting domains for {0}. Error: {1}", companyCode, ex.ToString()); } finally { if (db != null) { db.Dispose(); } } var htmlSelectBox = string.Format("<select id='{0}' name='{1}' class='form-control'>{2}</select>", "DomainName", "DomainName", sb.ToString()); return(new NonEncodedHtmlString(htmlSelectBox)); }
public static IHtmlString GetCompanyPlans() { var sb = new StringBuilder(); CloudPanelContext db = null; try { db = new CloudPanelContext(Settings.ConnectionString); var plans = (from p in db.Plans_Organization orderby p.OrgPlanName select p).ToList(); foreach (var p in plans) { sb.AppendFormat("<option value='{0}'>{1}</option>", p.OrgPlanID, p.OrgPlanName); } } catch (Exception ex) { sb.AppendFormat("<option value='0' selected>{1}: {2}</option>", "ERROR", ex.Message); log.ErrorFormat("Error getting company plans. Error: {0}", ex.ToString()); } finally { if (db != null) { db.Dispose(); } } var htmlSelectBox = string.Format("<select id='{0}' name='{1}' class='form-control'>{2}{3}</select>", "OrgPlanID", "OrgPlanID", "<option value='0'> --- Create New --- </option>", sb.ToString()); return(new NonEncodedHtmlString(htmlSelectBox)); }
public DomainsModule(CloudPanelContext db) : base("Company") { Get["{CompanyCode}/Domains"] = parameters => { var domains = new List<Domain>(); try { string companyCode = parameters.CompanyCode; domains = (from d in db.Domains where d.CompanyCode == companyCode select d).ToList(); } catch (Exception ex) { log.Error("Error getting domains for " + parameters.CompanyCode, ex); } return View["Company/Domains/DomainList.cshtml", domains]; }; Get["{CompanyCode}/Domains/Add"] = parameters => { // We are adding a domain return View["Company/Domains/DomainList.cshtml"]; }; Get["{CompanyCode}/Domains/{DomainName}/Edit"] = parameters => { // We are editing a domain return View["Company/Domains/DomainList.cshtml"]; }; Post["{CompanyCode}/Domains/{DomainName}/Delete"] = parameters => { // Check that domain belongs to this company // Delete domain string returnUrl = string.Format("~/Company/{0}/Domains", parameters.CompanyCode); return Response.AsRedirect(returnUrl); // Return to list of domains which will repopulate data }; }
public static IHtmlString GetActiveSyncPlans(string companyCode, List <Plans_ExchangeActiveSync> plans, int selectedID) { var sb = new StringBuilder(); CloudPanelContext db = null; try { db = new CloudPanelContext(Settings.ConnectionString); foreach (var p in plans) { sb.AppendFormat("<option value='{0}' {1}>{2}</option>", p.ASID, p.ASID == selectedID ? "selected" : "", p.DisplayName); } } catch (Exception ex) { sb.AppendFormat("<option value='0' selected>{1}: {2}</option>", "ERROR", ex.Message); log.ErrorFormat("Error getting activesync plans for {0}. Error: {1}", companyCode, ex.ToString()); } finally { if (db != null) { db.Dispose(); } } var htmlSelectBox = string.Format("<select id='{0}' name='{1}' class='form-control'>{2}{3}</select>", "ActiveSyncPlan", "ActiveSyncPlan", "<option value='0'> --- None --- </option>", sb.ToString()); return(new NonEncodedHtmlString(htmlSelectBox)); }
public DomainsModule(CloudPanelContext db) : base("Company") { Get["{CompanyCode}/Domains"] = parameters => { var domains = new List <Domain>(); try { string companyCode = parameters.CompanyCode; domains = (from d in db.Domains where d.CompanyCode == companyCode select d).ToList(); } catch (Exception ex) { log.Error("Error getting domains for " + parameters.CompanyCode, ex); } return(View["Company/Domains/DomainList.cshtml", domains]); }; Get["{CompanyCode}/Domains/Add"] = parameters => { // We are adding a domain return(View["Company/Domains/DomainList.cshtml"]); }; Get["{CompanyCode}/Domains/{DomainName}/Edit"] = parameters => { // We are editing a domain return(View["Company/Domains/DomainList.cshtml"]); }; Post["{CompanyCode}/Domains/{DomainName}/Delete"] = parameters => { // Check that domain belongs to this company // Delete domain string returnUrl = string.Format("~/Company/{0}/Domains", parameters.CompanyCode); return(Response.AsRedirect(returnUrl)); // Return to list of domains which will repopulate data }; }
public static IHtmlString GetEmailDomains(string companyCode, List <Domain> domains, string emailDomain) { var sb = new StringBuilder(); CloudPanelContext db = null; try { db = new CloudPanelContext(Settings.ConnectionString); foreach (var d in domains) { sb.AppendFormat("<option value='{0}' {1}>{2}</option>", d.DomainID, d.Domain1.Equals(emailDomain, StringComparison.CurrentCultureIgnoreCase) ? "selected" : "", d.Domain1); } } catch (Exception ex) { sb.AppendFormat("<option value='0' selected>{1}: {2}</option>", "ERROR", ex.Message); log.ErrorFormat("Error getting domains for {0}. Error: {1}", companyCode, ex.ToString()); } finally { if (db != null) { db.Dispose(); } } var htmlSelectBox = string.Format("<select id='{0}' name='{1}' class='form-control'>{2}</select>", "DomainName", "DomainName", sb.ToString()); return(new NonEncodedHtmlString(htmlSelectBox)); }
public static IHtmlString GetActiveSyncPlans(string companyCode, List<Plans_ExchangeActiveSync> plans, int selectedID) { var sb = new StringBuilder(); CloudPanelContext db = null; try { db = new CloudPanelContext(Settings.ConnectionString); foreach (var p in plans) { sb.AppendFormat("<option value='{0}' {1}>{2}</option>", p.ASID, p.ASID == selectedID ? "selected" : "", p.DisplayName); } } catch (Exception ex) { sb.AppendFormat("<option value='0' selected>{1}: {2}</option>", "ERROR", ex.Message); log.ErrorFormat("Error getting activesync plans for {0}. Error: {1}", companyCode, ex.ToString()); } finally { if (db != null) db.Dispose(); } var htmlSelectBox = string.Format("<select id='{0}' name='{1}' class='form-control'>{2}{3}</select>", "ActiveSyncPlan", "ActiveSyncPlan", "<option value='0'> --- None --- </option>", sb.ToString()); return new NonEncodedHtmlString(htmlSelectBox); }
public static string FindAvailableCompanyCode(string companyName, CloudPanelContext db) { char[] charArray = companyName.ToCharArray(); charArray = Array.FindAll <char>(charArray, (c => (char.IsLetterOrDigit(c)))); string companyCode = new string(charArray); if (companyCode.Length < 3) { throw new FormatException(companyCode); } else { companyCode = companyCode.Substring(0, 3); int increment = 1; string newCompanyCode = companyCode; bool foundGoodCode = false; do { var found = (from c in db.Companies where c.CompanyCode.Equals(newCompanyCode, StringComparison.CurrentCultureIgnoreCase) select c).Count(); if (found > 0) { newCompanyCode = string.Format("{0}{1}", companyCode, increment); increment = increment + 1; } else { foundGoodCode = true; } }while (!foundGoodCode); return(newCompanyCode.ToUpper()); } }
public Companies() { this.db = new CloudPanelContext(Settings.ConnectionString); }
public Resellers() { this.db = new CloudPanelContext(Settings.ConnectionString); }
public static IHtmlString GetCompanyPlans() { var sb = new StringBuilder(); CloudPanelContext db = null; try { db = new CloudPanelContext(Settings.ConnectionString); var plans = (from p in db.Plans_Organization orderby p.OrgPlanName select p).ToList(); foreach (var p in plans) { sb.AppendFormat("<option value='{0}'>{1}</option>", p.OrgPlanID, p.OrgPlanName); } } catch (Exception ex) { sb.AppendFormat("<option value='0' selected>{1}: {2}</option>", "ERROR", ex.Message); log.ErrorFormat("Error getting company plans. Error: {0}", ex.ToString()); } finally { if (db != null) db.Dispose(); } var htmlSelectBox = string.Format("<select id='{0}' name='{1}' class='form-control'>{2}{3}</select>", "OrgPlanID", "OrgPlanID", "<option value='0'> --- Create New --- </option>", sb.ToString()); return new NonEncodedHtmlString(htmlSelectBox); }
public Resellers() { this.db = new CloudPanelContext(Settings.ConnectionString); }
public static IHtmlString GetEmailDomains(string companyCode) { var sb = new StringBuilder(); CloudPanelContext db = null; try { db = new CloudPanelContext(Settings.ConnectionString); var domains = from d in db.Domains where d.CompanyCode == companyCode orderby d.Domain1 select d; foreach (var d in domains) { sb.AppendFormat("<option value='{0}' {1}>{2}</option>", d.DomainID, d.IsDefault ? "selected" : "", d.Domain1); } } catch (Exception ex) { sb.AppendFormat("<option value='0' selected>{1}: {2}</option>", "ERROR", ex.Message); log.ErrorFormat("Error getting domains for {0}. Error: {1}", companyCode, ex.ToString()); } finally { if (db != null) db.Dispose(); } var htmlSelectBox = string.Format("<select id='{0}' name='{1}' class='form-control'>{2}</select>", "DomainName", "DomainName", sb.ToString()); return new NonEncodedHtmlString(htmlSelectBox); }
public AjaxModule(CloudPanelContext db) : base("/ajax") { this.db = db; #region Validation Post["/validation/domain"] = _ => { try { string domain = Request.Form.DomainName; // Validate the domain if (domain.Contains(" ") || !domain.Contains(".")) return Response.AsJson("Domain is not in correct format"); else { int exist = (from d in db.Domains where d.Domain1 == domain select d).Count(); if (exist == 0) return Response.AsJson(true); else return Response.AsJson("Domain is not available"); } } catch (Exception ex) { log.ErrorFormat("Error checking if domain is valid. Exception: {0}", ex.ToString()); return Response.AsJson("Unknown error. Contact support."); } }; #endregion #region Company Get["/company/{CompanyCode}/Plans/Mailbox/{MailboxPlanID}"] = _ => { try { int id = int.Parse(_.MailboxPlanID); var plan = (from p in db.Plans_ExchangeMailbox where p.MailboxPlanID == id select p).FirstOrDefault(); return Response.AsJson(plan, HttpStatusCode.OK); } catch (Exception ex) { log.ErrorFormat("Error retrieving mailbox plan {0}. Exception: {1}", _.MailboxPlanID, ex.ToString()); return Response.AsJson("Unknown error. Contact support.", HttpStatusCode.InternalServerError); } }; Get["/company/{CompanyCode}/Users"] = _ => { try { Users users = new Users(); List<User> foundUsers = users.GetUsers(_.CompanyCode); var search = Request.Query.sSearch.HasValue ? (string)Request.Query.sSearch : ""; // This is if we are searching.. if (!string.IsNullOrEmpty(search)) foundUsers = foundUsers.Where(c => ( c.DisplayName.IndexOf(search, 0, StringComparison.CurrentCultureIgnoreCase) != -1 || c.Email.IndexOf(search, 0, StringComparison.CurrentCultureIgnoreCase) != -1 || c.UserPrincipalName.IndexOf(search, 0, StringComparison.CurrentCultureIgnoreCase) != -1 || c.Department.IndexOf(search, 0, StringComparison.CurrentCultureIgnoreCase) != -1 )).ToList(); int start = Convert.ToInt32(Request.Query.iDisplayStart.ToString()); int length = Convert.ToInt32(Request.Query.iDisplayLength.ToString()); var totalRecords = foundUsers.Count(); var secho = Request.Query.sEcho; var sorting = Request.Query.sSortDir_0; if (sorting == "asc") { return Response.AsJson(new { aaData = foundUsers.OrderBy(x => x.DisplayName).Skip(start).Take(length), sEcho = secho, iTotalRecords = totalRecords, iTotalDisplayRecords = totalRecords }); } else { return Response.AsJson(new { aaData = foundUsers.OrderByDescending(x => x.DisplayName).Skip(start).Take(length), sEcho = secho.ToString(), iTotalRecords = totalRecords, iTotalDisplayRecords = totalRecords }); } } catch (Exception ex) { log.ErrorFormat("Error retrieving users under company {0}. Exception: {1}", _.CompanyCode, ex.ToString()); return Response.AsJson(new { aaData = new List<User>(), sEcho = "0", iTotalRecords = 0, iTotalDisplayRecords = 0 }, HttpStatusCode.InternalServerError); } }; #endregion #region Companies Get["/reseller/{resellercode}/companies"] = _ => { try { Resellers resellers = new Resellers(); List<Company> companies = resellers.GetCompanies(_.resellercode); var search = Request.Query.sSearch.HasValue ? ((string)Request.Query.sSearch).ToLower() : ""; // This is if we are searching.. if (!string.IsNullOrEmpty(search)) companies = companies.Where(c => ( c.CompanyName.ToLower().Contains(search) )).ToList(); int start = Convert.ToInt32(Request.Query.iDisplayStart.ToString()); int length = Convert.ToInt32(Request.Query.iDisplayLength.ToString()); var totalRecords = companies.Count(); var secho = Request.Query.sEcho; var sorting = Request.Query.sSortDir_0; if (sorting == "asc") { return Response.AsJson(new { aaData = companies.OrderBy(x => x.CompanyName).Skip(start).Take(length), sEcho = secho, iTotalRecords = totalRecords, iTotalDisplayRecords = totalRecords }); } else { return Response.AsJson(new { aaData = companies.OrderByDescending(x => x.CompanyName).Skip(start).Take(length), sEcho = secho.ToString(), iTotalRecords = totalRecords, iTotalDisplayRecords = totalRecords }); } } catch (Exception ex) { log.ErrorFormat("Error retrieving companies under reseller {0}. Exception: {1}", _.resellercode, ex.ToString()); return Response.AsJson(new { aaData = new List<Company>(), sEcho = "0", iTotalRecords = 0, iTotalDisplayRecords = 0 }, HttpStatusCode.InternalServerError); } }; #endregion #region Charting Get["/charts/customers/top/{x}"] = _ => { List<TopXCustomers> topx = new List<TopXCustomers>(); SqlConnection sql = null; SqlCommand cmd = null; try { string query = string.Format(@"SELECT TOP {0} u.CompanyCode, c.CompanyName, COUNT(*) as TotalUsers FROM Users u INNER JOIN Companies c ON u.CompanyCode=c.CompanyCode GROUP BY u.CompanyCode, c.CompanyName ORDER BY COUNT(*) DESC", _.x); sql = new SqlConnection(Settings.ConnectionString); cmd = new SqlCommand(query, sql); sql.Open(); SqlDataReader r = cmd.ExecuteReader(); while (r.Read()) { topx.Add(new TopXCustomers() { CompanyCode = r["CompanyCode"].ToString(), CompanyName = r["CompanyName"].ToString(), TotalUsers = int.Parse(r["TotalUsers"].ToString()), TotalMailboxes = 0, TotalExchInMBUsed = 0, TotalExchInMBAllocated = 0 }); } r.Dispose(); // We have our top X customers now we must retrieve data. foreach (var top in topx) { var mailboxUsers = (from u in db.Users where u.CompanyCode == top.CompanyCode where u.MailboxPlan > 0 select u).ToList(); top.TotalMailboxes = mailboxUsers.Count; var plans = from p in db.Plans_ExchangeMailbox select p; foreach (var u in mailboxUsers) { int planTotal = (from p in plans where p.MailboxPlanID == u.MailboxPlan select p.MailboxSizeMB).First(); int addedToPlan = u.AdditionalMB > 0 ? (int)u.AdditionalMB : 0; top.TotalExchInMBAllocated = planTotal + addedToPlan; cmd.Parameters.Clear(); cmd.CommandText = "SELECT TOP 1 TotalItemSizeInKB FROM SvcMailboxSizes WHERE UserPrincipalName=@UserPrincipalName ORDER BY Retrieved DESC"; cmd.Parameters.AddWithValue("UserPrincipalName", u.UserPrincipalName); object val = cmd.ExecuteScalar(); if (val != DBNull.Value && val != null) { top.TotalExchInMBUsed += decimal.Round(decimal.Parse(val.ToString()) / 1024); } } } } catch (Exception ex) { log.ErrorFormat("Error retrieving Top X Customers. Error: {0}", ex.ToString()); } finally { if (cmd != null) cmd.Dispose(); if (sql != null) sql.Dispose(); } return Response.AsJson(topx, HttpStatusCode.OK); }; Get["/charts/{CompanyCode}/overview"] = _ => { // Set default values Dictionary<string, int> data = new Dictionary<string, int>(); data.Add("MaxUsers", 0); data.Add("Users", 0); data.Add("Mailboxes", 0); data.Add("Citrix Users", 0); data.Add("Lync Users", 0); data.Add("Distribution Groups", 0); data.Add("Contacts", 0); // Query database for actual values try { string companyCode = _.CompanyCode; if (string.IsNullOrEmpty(companyCode)) throw new Exception("Company code was null"); var company = (from c in db.Companies where !c.IsReseller where c.CompanyCode == companyCode select c).First(); var companyUsers = from u in db.Users where u.CompanyCode == companyCode select u; var userIds = from u in companyUsers select u.ID; data["MaxUsers"] = (from p in db.Plans_Organization where p.OrgPlanID == company.OrgPlanID select p.MaxUsers).First(); data["Users"] = companyUsers.Count(); data["Mailboxes"] = (from u in companyUsers where u.MailboxPlan > 0 select u).Count(); data["Citrix Users"] = (from u in db.UserPlansCitrix where userIds.Contains(u.UserID) select u.UserID).Distinct().Count(); data["Lync Users"] = 0; data["Distribution Groups"] = (from d in db.DistributionGroups where d.CompanyCode == companyCode select d).Count(); data["Contacts"] = (from c in db.Contacts where c.CompanyCode == companyCode select c).Count(); } catch (Exception ex) { log.ErrorFormat("Error retrieving company overview column chart. Error: {0}", ex.ToString()); } return Response.AsJson(data, HttpStatusCode.OK); }; #endregion #region Plans Get["/plans/company/{OrgPlanID}"] = _ => { try { int planId = _.OrgPlanID; var plan = (from p in db.Plans_Organization where p.OrgPlanID == planId select p).FirstOrDefault(); return Response.AsJson(plan, HttpStatusCode.OK); } catch (Exception ex) { log.ErrorFormat("Error retrieving company plans. Error: {0}", ex.ToString()); return HttpStatusCode.InternalServerError; } }; #endregion }
public AjaxModule(CloudPanelContext db) : base("/ajax") { this.db = db; #region Validation Post["/validation/domain"] = _ => { try { string domain = Request.Form.DomainName; // Validate the domain if (domain.Contains(" ") || !domain.Contains(".")) { return(Response.AsJson("Domain is not in correct format")); } else { int exist = (from d in db.Domains where d.Domain1 == domain select d).Count(); if (exist == 0) { return(Response.AsJson(true)); } else { return(Response.AsJson("Domain is not available")); } } } catch (Exception ex) { log.ErrorFormat("Error checking if domain is valid. Exception: {0}", ex.ToString()); return(Response.AsJson("Unknown error. Contact support.")); } }; #endregion #region Company Get["/company/{CompanyCode}/Plans/Mailbox/{MailboxPlanID}"] = _ => { try { int id = int.Parse(_.MailboxPlanID); var plan = (from p in db.Plans_ExchangeMailbox where p.MailboxPlanID == id select p).FirstOrDefault(); return(Response.AsJson(plan, HttpStatusCode.OK)); } catch (Exception ex) { log.ErrorFormat("Error retrieving mailbox plan {0}. Exception: {1}", _.MailboxPlanID, ex.ToString()); return(Response.AsJson("Unknown error. Contact support.", HttpStatusCode.InternalServerError)); } }; Get["/company/{CompanyCode}/Users"] = _ => { try { Users users = new Users(); List <User> foundUsers = users.GetUsers(_.CompanyCode); var search = Request.Query.sSearch.HasValue ? (string)Request.Query.sSearch : ""; // This is if we are searching.. if (!string.IsNullOrEmpty(search)) { foundUsers = foundUsers.Where(c => ( c.DisplayName.IndexOf(search, 0, StringComparison.CurrentCultureIgnoreCase) != -1 || c.Email.IndexOf(search, 0, StringComparison.CurrentCultureIgnoreCase) != -1 || c.UserPrincipalName.IndexOf(search, 0, StringComparison.CurrentCultureIgnoreCase) != -1 || c.Department.IndexOf(search, 0, StringComparison.CurrentCultureIgnoreCase) != -1 )).ToList(); } int start = Convert.ToInt32(Request.Query.iDisplayStart.ToString()); int length = Convert.ToInt32(Request.Query.iDisplayLength.ToString()); var totalRecords = foundUsers.Count(); var secho = Request.Query.sEcho; var sorting = Request.Query.sSortDir_0; if (sorting == "asc") { return(Response.AsJson(new { aaData = foundUsers.OrderBy(x => x.DisplayName).Skip(start).Take(length), sEcho = secho, iTotalRecords = totalRecords, iTotalDisplayRecords = totalRecords })); } else { return(Response.AsJson(new { aaData = foundUsers.OrderByDescending(x => x.DisplayName).Skip(start).Take(length), sEcho = secho.ToString(), iTotalRecords = totalRecords, iTotalDisplayRecords = totalRecords })); } } catch (Exception ex) { log.ErrorFormat("Error retrieving users under company {0}. Exception: {1}", _.CompanyCode, ex.ToString()); return(Response.AsJson(new { aaData = new List <User>(), sEcho = "0", iTotalRecords = 0, iTotalDisplayRecords = 0 }, HttpStatusCode.InternalServerError)); } }; #endregion #region Companies Get["/reseller/{resellercode}/companies"] = _ => { try { Resellers resellers = new Resellers(); List <Company> companies = resellers.GetCompanies(_.resellercode); var search = Request.Query.sSearch.HasValue ? ((string)Request.Query.sSearch).ToLower() : ""; // This is if we are searching.. if (!string.IsNullOrEmpty(search)) { companies = companies.Where(c => ( c.CompanyName.ToLower().Contains(search) )).ToList(); } int start = Convert.ToInt32(Request.Query.iDisplayStart.ToString()); int length = Convert.ToInt32(Request.Query.iDisplayLength.ToString()); var totalRecords = companies.Count(); var secho = Request.Query.sEcho; var sorting = Request.Query.sSortDir_0; if (sorting == "asc") { return(Response.AsJson(new { aaData = companies.OrderBy(x => x.CompanyName).Skip(start).Take(length), sEcho = secho, iTotalRecords = totalRecords, iTotalDisplayRecords = totalRecords })); } else { return(Response.AsJson(new { aaData = companies.OrderByDescending(x => x.CompanyName).Skip(start).Take(length), sEcho = secho.ToString(), iTotalRecords = totalRecords, iTotalDisplayRecords = totalRecords })); } } catch (Exception ex) { log.ErrorFormat("Error retrieving companies under reseller {0}. Exception: {1}", _.resellercode, ex.ToString()); return(Response.AsJson(new { aaData = new List <Company>(), sEcho = "0", iTotalRecords = 0, iTotalDisplayRecords = 0 }, HttpStatusCode.InternalServerError)); } }; #endregion #region Charting Get["/charts/customers/top/{x}"] = _ => { List <TopXCustomers> topx = new List <TopXCustomers>(); SqlConnection sql = null; SqlCommand cmd = null; try { string query = string.Format(@"SELECT TOP {0} u.CompanyCode, c.CompanyName, COUNT(*) as TotalUsers FROM Users u INNER JOIN Companies c ON u.CompanyCode=c.CompanyCode GROUP BY u.CompanyCode, c.CompanyName ORDER BY COUNT(*) DESC", _.x); sql = new SqlConnection(Settings.ConnectionString); cmd = new SqlCommand(query, sql); sql.Open(); SqlDataReader r = cmd.ExecuteReader(); while (r.Read()) { topx.Add(new TopXCustomers() { CompanyCode = r["CompanyCode"].ToString(), CompanyName = r["CompanyName"].ToString(), TotalUsers = int.Parse(r["TotalUsers"].ToString()), TotalMailboxes = 0, TotalExchInMBUsed = 0, TotalExchInMBAllocated = 0 }); } r.Dispose(); // We have our top X customers now we must retrieve data. foreach (var top in topx) { var mailboxUsers = (from u in db.Users where u.CompanyCode == top.CompanyCode where u.MailboxPlan > 0 select u).ToList(); top.TotalMailboxes = mailboxUsers.Count; var plans = from p in db.Plans_ExchangeMailbox select p; foreach (var u in mailboxUsers) { int planTotal = (from p in plans where p.MailboxPlanID == u.MailboxPlan select p.MailboxSizeMB).First(); int addedToPlan = u.AdditionalMB > 0 ? (int)u.AdditionalMB : 0; top.TotalExchInMBAllocated = planTotal + addedToPlan; cmd.Parameters.Clear(); cmd.CommandText = "SELECT TOP 1 TotalItemSizeInKB FROM SvcMailboxSizes WHERE UserPrincipalName=@UserPrincipalName ORDER BY Retrieved DESC"; cmd.Parameters.AddWithValue("UserPrincipalName", u.UserPrincipalName); object val = cmd.ExecuteScalar(); if (val != DBNull.Value && val != null) { top.TotalExchInMBUsed += decimal.Round(decimal.Parse(val.ToString()) / 1024); } } } } catch (Exception ex) { log.ErrorFormat("Error retrieving Top X Customers. Error: {0}", ex.ToString()); } finally { if (cmd != null) { cmd.Dispose(); } if (sql != null) { sql.Dispose(); } } return(Response.AsJson(topx, HttpStatusCode.OK)); }; Get["/charts/{CompanyCode}/overview"] = _ => { // Set default values Dictionary <string, int> data = new Dictionary <string, int>(); data.Add("MaxUsers", 0); data.Add("Users", 0); data.Add("Mailboxes", 0); data.Add("Citrix Users", 0); data.Add("Lync Users", 0); data.Add("Distribution Groups", 0); data.Add("Contacts", 0); // Query database for actual values try { string companyCode = _.CompanyCode; if (string.IsNullOrEmpty(companyCode)) { throw new Exception("Company code was null"); } var company = (from c in db.Companies where !c.IsReseller where c.CompanyCode == companyCode select c).First(); var companyUsers = from u in db.Users where u.CompanyCode == companyCode select u; var userIds = from u in companyUsers select u.ID; data["MaxUsers"] = (from p in db.Plans_Organization where p.OrgPlanID == company.OrgPlanID select p.MaxUsers).First(); data["Users"] = companyUsers.Count(); data["Mailboxes"] = (from u in companyUsers where u.MailboxPlan > 0 select u).Count(); data["Citrix Users"] = (from u in db.UserPlansCitrix where userIds.Contains(u.UserID) select u.UserID).Distinct().Count(); data["Lync Users"] = 0; data["Distribution Groups"] = (from d in db.DistributionGroups where d.CompanyCode == companyCode select d).Count(); data["Contacts"] = (from c in db.Contacts where c.CompanyCode == companyCode select c).Count(); } catch (Exception ex) { log.ErrorFormat("Error retrieving company overview column chart. Error: {0}", ex.ToString()); } return(Response.AsJson(data, HttpStatusCode.OK)); }; #endregion #region Plans Get["/plans/company/{OrgPlanID}"] = _ => { try { int planId = _.OrgPlanID; var plan = (from p in db.Plans_Organization where p.OrgPlanID == planId select p).FirstOrDefault(); return(Response.AsJson(plan, HttpStatusCode.OK)); } catch (Exception ex) { log.ErrorFormat("Error retrieving company plans. Error: {0}", ex.ToString()); return(HttpStatusCode.InternalServerError); } }; #endregion }
public static IHtmlString GetEmailDomains(string companyCode, List<Domain> domains, string emailDomain) { var sb = new StringBuilder(); CloudPanelContext db = null; try { db = new CloudPanelContext(Settings.ConnectionString); foreach (var d in domains) { sb.AppendFormat("<option value='{0}' {1}>{2}</option>", d.DomainID, d.Domain1.Equals(emailDomain, StringComparison.CurrentCultureIgnoreCase) ? "selected" : "", d.Domain1); } } catch (Exception ex) { sb.AppendFormat("<option value='0' selected>{1}: {2}</option>", "ERROR", ex.Message); log.ErrorFormat("Error getting domains for {0}. Error: {1}", companyCode, ex.ToString()); } finally { if (db != null) db.Dispose(); } var htmlSelectBox = string.Format("<select id='{0}' name='{1}' class='form-control'>{2}</select>", "DomainName", "DomainName", sb.ToString()); return new NonEncodedHtmlString(htmlSelectBox); }
public PlansModule(CloudPanelContext db) : base("Plans") { //this.RequiresAuthentication(); //this.RequiresAnyClaim(new[] { "SuperAdmin" }); Get["/Mailbox"] = parameters => { List<MailboxPlanObject> plans = new List<MailboxPlanObject>(); plans.Add(new MailboxPlanObject() { MailboxPlanID = 1, MailboxPlanName = "Bronze" }); ViewBag.Plans = plans; return View["Plans/MailboxPlans.cshtml"]; }; Get["/Company"] = parameters => { try { var plans = (from p in db.Plans_Organization select p).ToList(); return View["Plans/CompanyPlans.cshtml", plans]; } catch (Exception ex) { log.Error("Error retrieving company plans", ex); return View["Plans/CompanyPlans.cshtml", null]; } }; Post["/Company/Update"] = parameters => { var formModel = this.Bind<Plans_Organization>(); try { if (formModel.OrgPlanID <= 0) { db.Plans_Organization.Add(formModel); db.SaveChanges(); } else { var plan = (from p in db.Plans_Organization where p.OrgPlanID == formModel.OrgPlanID select p).FirstOrDefault(); plan.OrgPlanName = formModel.OrgPlanName; plan.MaxUsers = formModel.MaxUsers; plan.MaxDomains = formModel.MaxDomains; plan.MaxExchangeMailboxes = formModel.MaxExchangeMailboxes; plan.MaxExchangeContacts = formModel.MaxExchangeContacts; plan.MaxExchangeDistLists = formModel.MaxExchangeDistLists; plan.MaxExchangeResourceMailboxes = formModel.MaxExchangeResourceMailboxes; plan.MaxExchangeMailPublicFolders = formModel.MaxExchangeMailPublicFolders; db.SaveChanges(); } } catch (Exception ex) { log.Error("Error retrieving company plans", ex); } return Response.AsRedirect("~/Plans/Company"); }; }
public PlansModule(CloudPanelContext db) : base("Plans") { //this.RequiresAuthentication(); //this.RequiresAnyClaim(new[] { "SuperAdmin" }); Get["/Mailbox"] = parameters => { List <MailboxPlanObject> plans = new List <MailboxPlanObject>(); plans.Add(new MailboxPlanObject() { MailboxPlanID = 1, MailboxPlanName = "Bronze" }); ViewBag.Plans = plans; return(View["Plans/MailboxPlans.cshtml"]); }; Get["/Company"] = parameters => { try { var plans = (from p in db.Plans_Organization select p).ToList(); return(View["Plans/CompanyPlans.cshtml", plans]); } catch (Exception ex) { log.Error("Error retrieving company plans", ex); return(View["Plans/CompanyPlans.cshtml", null]); } }; Post["/Company/Update"] = parameters => { var formModel = this.Bind <Plans_Organization>(); try { if (formModel.OrgPlanID <= 0) { db.Plans_Organization.Add(formModel); db.SaveChanges(); } else { var plan = (from p in db.Plans_Organization where p.OrgPlanID == formModel.OrgPlanID select p).FirstOrDefault(); plan.OrgPlanName = formModel.OrgPlanName; plan.MaxUsers = formModel.MaxUsers; plan.MaxDomains = formModel.MaxDomains; plan.MaxExchangeMailboxes = formModel.MaxExchangeMailboxes; plan.MaxExchangeContacts = formModel.MaxExchangeContacts; plan.MaxExchangeDistLists = formModel.MaxExchangeDistLists; plan.MaxExchangeResourceMailboxes = formModel.MaxExchangeResourceMailboxes; plan.MaxExchangeMailPublicFolders = formModel.MaxExchangeMailPublicFolders; db.SaveChanges(); } } catch (Exception ex) { log.Error("Error retrieving company plans", ex); } return(Response.AsRedirect("~/Plans/Company")); }; }
public Companies() { this.db = new CloudPanelContext(Settings.ConnectionString); }