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); }