protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(this.GetType());

            Page.RegisterBodyScripts(ResolveUrl("~/usercontrols/management/maildomainsettings/js/maildomainsettings.js"));
            Page.RegisterStyleControl(VirtualPathUtility.ToAbsolute("~/usercontrols/management/maildomainsettings/css/maildomainsettings.less"));

            _currentTenant = CoreContext.TenantManager.GetCurrentTenant();
            _studioTrustedDomainSettings = SettingsManager.Instance.LoadSettings<StudioTrustedDomainSettings>(TenantProvider.CurrentTenantID);
            _enableInviteUsers = TenantStatisticsProvider.GetUsersCount() < TenantExtra.GetTenantQuota().ActiveUsers;

            if (!_enableInviteUsers)
                _studioTrustedDomainSettings.InviteUsersAsVisitors = true;
        }
        public object SaveMailDomainSettings(TenantTrustedDomainsType type, List<string> domains, bool inviteUsersAsVisitors)
        {
            try
            {
                SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

                var tenant = CoreContext.TenantManager.GetCurrentTenant();

                if (type == TenantTrustedDomainsType.Custom)
                {
                    tenant.TrustedDomains.Clear();
                    foreach (var d in domains.Select(domain => (domain ?? "").Trim().ToLower()))
                    {
                        if (!CheckTrustedDomain(d))
                            return new {Status = 0, Message = Resource.ErrorNotCorrectTrustedDomain};

                        tenant.TrustedDomains.Add(d);
                    }
                }

                tenant.TrustedDomainsType = tenant.TrustedDomains.Count == 0 ? TenantTrustedDomainsType.None : type;

                var domainSettingsObj = new StudioTrustedDomainSettings {InviteUsersAsVisitors = inviteUsersAsVisitors};
                SettingsManager.Instance.SaveSettings(domainSettingsObj, TenantProvider.CurrentTenantID);

                CoreContext.TenantManager.SaveTenant(tenant);

                AdminLog.PostAction("Settings: saved mail domain settings with parameters type={0}, domains={1}, inviteUsersAsVisitors={2}", type, string.Join("|", domains.ToArray()), inviteUsersAsVisitors.ToString());
                MessageService.Send(HttpContext.Current.Request, MessageAction.TrustedMailDomainSettingsUpdated);

                return new {Status = 1, Message = Resource.SuccessfullySaveSettingsMessage};
            }
            catch(Exception e)
            {
                return new {Status = 0, Message = e.Message.HtmlEncode()};
            }
        }