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); }
public void RedirectionController_Save_Valid_Redirection() { var redirection = new Redirection { Name = "Test R", PortalId = Portal0, SortOrder = 1, SourceTabId = -1, Type = RedirectionType.MobilePhone, TargetType = TargetType.Portal, TargetValue = Portal1 }; _redirectionController.Save(redirection); var dataReader = _dataProvider.Object.GetRedirections(Portal0); var affectedCount = 0; while (dataReader.Read()) { affectedCount++; } Assert.AreEqual(1, affectedCount); }
public void RedirectionController_Save_ValidRedirection_With_Rules() { var redirection = new Redirection { Name = "Test R", PortalId = Portal0, SortOrder = 1, SourceTabId = -1, IncludeChildTabs = true, Type = RedirectionType.Other, TargetType = TargetType.Portal, TargetValue = Portal1 }; redirection.MatchRules.Add(new MatchRule { Capability = "Platform", Expression = "IOS" }); redirection.MatchRules.Add(new MatchRule { Capability = "Version", Expression = "5" }); _redirectionController.Save(redirection); var dataReader = _dataProvider.Object.GetRedirections(Portal0); var affectedCount = 0; while (dataReader.Read()) { affectedCount++; } Assert.AreEqual(1, affectedCount); var getRe = _redirectionController.GetRedirectionsByPortal(Portal0)[0]; Assert.AreEqual(2, getRe.MatchRules.Count); }
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); }