private void lnkSave_OnClick(object sender, EventArgs e)
 {
     // Checks for duplicate names
     var name = txtRedirectName.Text;
     var nameCount = new RedirectionController().GetRedirectionsByPortal(ModuleContext.PortalId).Count(r => r.Name.ToLower() == name.ToLower());
     if (nameCount < 1)
     {
         SaveRedirection();
         Response.Redirect(Globals.NavigateURL(""), true);
     }
     else
     {
         UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("DuplicateNameError.Text", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
     }          
 }
        protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

            var redirectionController = new RedirectionController();
            var redirectUrl = redirectionController.GetMobileSiteUrl();
            if (!string.IsNullOrEmpty(redirectUrl))
            {                
                lnkPortal.NavigateUrl = redirectUrl;                
                lnkPortal.Text = Localization.GetString("lnkPortal", LocalResourcesFile);
            }
            else
            {
                this.Visible = false;                    
            }
        }
Example #3
0
        private void UpdateRules()
        {
            var mapCapabilites = CreateMappedCapabilities();
            IRedirectionController controller = new RedirectionController();
            var redirections = controller.GetAllRedirections();
            foreach (var redirection in redirections.Where(redirection => redirection.MatchRules.Count > 0))
            {
                var deletedRules = new List<IMatchRule>();
                foreach (var rule in redirection.MatchRules)
                {
                    if (rule.Capability == "pointing_method")
                    {
                        switch (rule.Expression)
                        {
                            case "clickwheel":
                                rule.Capability = "HasClickWheel";
                                rule.Expression = "True";
                                break;
                            case "touchscreen":
                                rule.Capability = "HasTouchScreen";
                                rule.Expression = "True";
                                break;
                            default:
                                deletedRules.Add(rule);
                                break;
                        }
                    }
                    else
                    {
                        if (mapCapabilites.ContainsKey(rule.Capability))
                        {
                            rule.Capability = mapCapabilites[rule.Capability];
                            switch (rule.Expression)
                            {
                                case "true":
                                    rule.Expression = "True";
                                    break;
                                case "false":
                                    rule.Expression = "False";
                                    break;
                            }
                        }
                        else
                        {
                            deletedRules.Add(rule);
                        }
                    }
                    
                }

                //remove the deleted rules
                foreach (var deletedRule in deletedRules)
                {
                    controller.DeleteRule(redirection.PortalId, redirection.Id, deletedRule.Id);
                    redirection.MatchRules.Remove(deletedRule);
                }

                controller.Save(redirection);
            }

        }
 private bool HomePageRedirectExists()
 {
     var redirectionController = new RedirectionController();
     var homeRedirects = redirectionController.GetRedirectionsByPortal(ModuleContext.PortalId).Where(r => r.SourceTabId == ModuleContext.PortalSettings.HomeTabId);
     return (homeRedirects.Any());
 }
        private void lnkSave_OnClick(object sender, EventArgs e)
        {
                     
            var redirectionController = new RedirectionController();
            var name = txtRedirectName.Text;
            int nameCount;
            // Checks for duplicate names   
            if (RedirectId > Null.NullInteger)
            {
                nameCount = redirectionController.GetRedirectionsByPortal(ModuleContext.PortalId).Where(r =>( r.Id != RedirectId && r.Name.ToLower() == name.ToLower())).Count();
            }
            else
            {
                nameCount = redirectionController.GetRedirectionsByPortal(ModuleContext.PortalId).Where(r => r.Name.ToLower() == name.ToLower()).Count();
            }

            if (nameCount < 1)
            {
                SaveRedirection();
                Response.Redirect(Globals.NavigateURL("", "type=RedirectionSettings"), true);
            }
            else
            {
                DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("DuplicateNameError.Text", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);                
            }            
        }
        private void SaveRedirection()
        {
            var redirection = new Redirection();
            var redirectionController = new RedirectionController();

            redirection.Name = (HomePageRedirectExists()) ? txtRedirectName.Text : Localization.GetString("DefaultRedirectName.Text", LocalResourceFile);
            redirection.Enabled = true;
            redirection.PortalId = ModuleContext.PortalId;
            redirection.SourceTabId = (cboSourcePage.Visible) ? cboSourcePage.SelectedItemValueAsInt : ModuleContext.PortalSettings.HomeTabId;

            redirection.Type = RedirectionType.MobilePhone;
            redirection.TargetType = (TargetType) Enum.Parse(typeof (TargetType), optRedirectTarget.SelectedValue);

            switch (redirection.TargetType)
            {
                case TargetType.Portal:
                    redirection.TargetValue = cboPortal.SelectedItem.Value;
                    break;
                case TargetType.Tab:
                    redirection.TargetValue = cboTargetPage.SelectedItemValueAsInt;
                    break;
                case TargetType.Url:
                    redirection.TargetValue = txtTargetUrl.Text;
                    break;
            }

            // Save the redirect
            redirectionController.Save(redirection);
        }
        private void SaveRedirection()
        {
            IRedirection redirection = new Redirection();
            var redirectionController = new RedirectionController();

            if (RedirectId > Null.NullInteger)
            {
                redirection = redirectionController.GetRedirectionById(ModuleContext.PortalId, RedirectId);
            }

            redirection.Name = txtRedirectName.Text;
            redirection.Enabled = chkEnable.Checked;
            redirection.PortalId = ModuleContext.PortalId;
            if (optRedirectSource.SelectedValue == "Tab")
            {
                redirection.SourceTabId = int.Parse(cboSourcePage.SelectedValue);
                redirection.IncludeChildTabs = chkChildPages.Checked;
            }
            else
            {
                redirection.SourceTabId = -1;
                redirection.IncludeChildTabs = false;
            }

            redirection.Type = (RedirectionType)Enum.Parse(typeof(RedirectionType), optRedirectType.SelectedValue);
            //Other, save new capabilities
            if (redirection.Type == RedirectionType.Other)
            {
                if (RedirectId > Null.NullInteger)
                {
                    // Delete capabilities that no longer exist in the grid
                    foreach (var rule in redirection.MatchRules.Where(rule => Capabilities.Where(c => c.Id == rule.Id).Count() < 1))
                    {
                        redirectionController.DeleteRule(ModuleContext.PortalId, redirection.Id, rule.Id);
                    }
                }

                // A new capabilities
                foreach (var capability in Capabilities.Where(capability => capability.Id == -1))
                {
                    redirection.MatchRules.Add(capability);
                }

                redirection.MatchRules = Capabilities;
            }
            else if (RedirectId > Null.NullInteger && redirection.MatchRules.Count > 0)
            {
                foreach(var rule in redirection.MatchRules)
                {
                    redirectionController.DeleteRule(ModuleContext.PortalId, redirection.Id, rule.Id);
                }
            }

            redirection.TargetType = (TargetType)Enum.Parse(typeof(TargetType), optRedirectTarget.SelectedValue);
            switch (redirection.TargetType)
            {
                case TargetType.Portal:
                    redirection.TargetValue = cboPortal.SelectedItem.Value;
                    break;
                case TargetType.Tab:
                    redirection.TargetValue = int.Parse(cboTargetPage.SelectedValue);
                    break;
                case TargetType.Url:
                    redirection.TargetValue = txtTargetUrl.Text;
                    break;
            }

            // Save the redirect
            redirectionController.Save(redirection);      
        }
        private void BindRedirection(int redirectId)
        {
            // Populating existing redirection settings
            if (redirectId != Null.NullInteger)
            {
                var redirectController = new RedirectionController();
                var redirect = redirectController.GetRedirectionById(ModuleContext.PortalId, redirectId);

                txtRedirectName.Text = redirect.Name;
                chkEnable.Checked = redirect.Enabled;
                chkChildPages.Checked = redirect.IncludeChildTabs;

                if (redirect.SourceTabId != -1)
                {
                    optRedirectSource.SelectedValue = "Tab";
                    cboSourcePage.SelectedIndex = cboSourcePage.Items.IndexOf(cboSourcePage.Items.FindByValue(redirect.SourceTabId.ToString()));
                }
                else
                {
                    optRedirectSource.SelectedValue = "Portal";
                }

                optRedirectType.SelectedValue = redirect.Type.ToString();
                optRedirectTarget.SelectedValue = redirect.TargetType.ToString();

                //Other, populate Capabilities
                if (redirect.Type == RedirectionType.Other)
                {
                    BindRedirectionCapabilties();
                }

                switch (redirect.TargetType)
                {
                    case TargetType.Portal:
                        if (cboPortal.Items.Count < 1) optRedirectTarget.SelectedValue = "Tab";
                        else if (cboPortal.Items.FindByValue(redirect.TargetValue.ToString()) != null)
                            cboPortal.SelectedValue = redirect.TargetValue.ToString();
                        break;
                    case TargetType.Tab:
                        if (cboTargetPage.Items.FindByValue(redirect.TargetValue.ToString()) != null)
                            cboTargetPage.SelectedValue = redirect.TargetValue.ToString();
                        break;
                    case TargetType.Url:
                        txtTargetUrl.Text = redirect.TargetValue.ToString();
                        break;
                }
            }
        }
		public void SetUp()
		{
			ComponentFactory.Container = new SimpleContainer();
			_dataProvider = MockComponentProvider.CreateDataProvider();
			MockComponentProvider.CreateDataCacheProvider();
			MockComponentProvider.CreateEventLogController();
            _clientCapabilityProvider = MockComponentProvider.CreateNew<ClientCapabilityProvider>();

			_redirectionController = new RedirectionController();

			SetupDataProvider();
			SetupClientCapabilityProvider();
			SetupRoleProvider();
		}
        private void SaveRedirection()
        {
            IRedirection redirection = new Redirection();
            var redirectionController = new RedirectionController();

            if (RedirectId > Null.NullInteger)
            {
                redirection = redirectionController.GetRedirectionById(ModuleContext.PortalId, RedirectId);
            }

            redirection.Name = txtRedirectName.Text;
            redirection.Enabled = chkEnable.Checked;
            redirection.PortalId = ModuleContext.PortalId;
            if (optRedirectSource.SelectedValue == "Tab")
            {
                redirection.SourceTabId = cboSourcePage.SelectedItemValueAsInt;
                redirection.IncludeChildTabs = chkChildPages.Checked;
            }
            else
            {
                redirection.SourceTabId = -1;
                redirection.IncludeChildTabs = false;
            }

            redirection.Type = (RedirectionType)Enum.Parse(typeof(RedirectionType), optRedirectType.SelectedValue);
			if (redirection.Type == RedirectionType.SmartPhone && optRedirectType.SelectedValue != "")//save smart phone value to other type with capability match.
			{
				if (RedirectId > Null.NullInteger)
                {
                    // Delete capabilities that no longer exist in the grid
                    foreach (var rule in redirection.MatchRules)
                    {
                        redirectionController.DeleteRule(ModuleContext.PortalId, redirection.Id, rule.Id);
                    }
                }

				redirection.Type = RedirectionType.Other;
				redirection.MatchRules.Add(new MatchRule(){Capability = "IsSmartPhone", Expression = "True"});
			}
			else if (redirection.Type == RedirectionType.Other)//Other, save new capabilities
            {
                if (RedirectId > Null.NullInteger)
                {
                    // Delete capabilities that no longer exist in the grid
                    foreach (var rule in redirection.MatchRules.Where(rule => Capabilities.All(c => c.Id != rule.Id)))
                    {
                        redirectionController.DeleteRule(ModuleContext.PortalId, redirection.Id, rule.Id);
                    }
                }

                redirection.MatchRules = Capabilities;
            }
            else if (RedirectId > Null.NullInteger && redirection.MatchRules.Count > 0)
            {
                foreach(var rule in redirection.MatchRules)
                {
                    redirectionController.DeleteRule(ModuleContext.PortalId, redirection.Id, rule.Id);
                }
            }

            redirection.TargetType = (TargetType)Enum.Parse(typeof(TargetType), optRedirectTarget.SelectedValue);
            switch (redirection.TargetType)
            {
                case TargetType.Portal:
                    redirection.TargetValue = cboPortal.SelectedItem.Value;
                    break;
                case TargetType.Tab:
                    redirection.TargetValue = cboTargetPage.SelectedItemValueAsInt;
                    break;
                case TargetType.Url:
                    redirection.TargetValue = txtTargetUrl.Text;
                    break;
            }

            // Save the redirect
            redirectionController.Save(redirection);      
        }
        private void BindRedirection(int redirectId)
        {
            // Populating existing redirection settings
            if (redirectId != Null.NullInteger)
            {
                var redirectController = new RedirectionController();
                var redirect = redirectController.GetRedirectionById(ModuleContext.PortalId, redirectId);

                txtRedirectName.Text = redirect.Name;
                chkEnable.Checked = redirect.Enabled;
                chkChildPages.Checked = redirect.IncludeChildTabs;
                var tabs = new TabController().GetTabsByPortal(ModuleContext.PortalId).AsList().Where(IsVisible);
                var tabInfos = tabs as IList<TabInfo> ?? tabs.ToList();
                if (redirect.SourceTabId != -1)
                {
                    optRedirectSource.SelectedValue = "Tab";
                    cboSourcePage.SelectedPage = tabInfos.SingleOrDefault(t => t.TabID == redirect.SourceTabId);
                }
                else
                {
                    optRedirectSource.SelectedValue = "Portal";
                }

				if (IsSmartPhoneRedirect(redirect))
				{
					optRedirectType.SelectedValue = "SmartPhone";
				}
				else
				{
					optRedirectType.SelectedValue = redirect.Type.ToString();
				}

                optRedirectTarget.SelectedValue = redirect.TargetType.ToString();

                //Other, populate Capabilities
                if (redirect.Type == RedirectionType.Other)
                {
                    BindRedirectionCapabilties();
                }

                switch (redirect.TargetType)
                {
                    case TargetType.Portal:
                        if (cboPortal.Items.Count < 1) optRedirectTarget.SelectedValue = "Tab";
                        else
                            cboPortal.Select(redirect.TargetValue.ToString(), false);
                        break;
                    case TargetType.Tab:
                        int redirectTargetInt;
                        if(int.TryParse(redirect.TargetValue.ToString(), out redirectTargetInt))
                            cboTargetPage.SelectedPage = tabInfos.SingleOrDefault(t => t.TabID == redirectTargetInt);
                        break;
                    case TargetType.Url:
                        txtTargetUrl.Text = redirect.TargetValue.ToString();
                        break;
                }
            }
        }