/// <summary> /// Creates new AB variant if AB test filled in. /// </summary> /// <param name="newDocument">Newly created document</param> /// <returns>True if new variant is successfully created or if AB test is not defined.</returns> private bool CreateABVariant(TreeNode newDocument) { // If ABTest selected - create new variant int abTestID = ValidationHelper.GetInteger(ucABTestSelector.Value, 0); if (abTestID <= 0) { return(true); } // If no test found, handle it as no test was specified ABTestInfo abTest = ABTestInfoProvider.GetABTestInfo(abTestID); if (abTest == null) { return(true); } string defaultCodeName = TextHelper.LimitLength(ValidationHelper.GetCodeName(newDocument.NodeAlias), 45, String.Empty); string codeName = defaultCodeName; ABVariantInfo info = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, SiteContext.CurrentSiteName); // Find non existing variant code name int index = 0; while (info != null) { index++; codeName = defaultCodeName + "-" + index; info = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, SiteContext.CurrentSiteName); } // Save AB Variant ABVariantInfo variantInfo = new ABVariantInfo(); variantInfo.ABVariantTestID = abTestID; variantInfo.ABVariantPath = newDocument.NodeAliasPath; variantInfo.ABVariantName = codeName; variantInfo.ABVariantDisplayName = newDocument.NodeAlias; variantInfo.ABVariantSiteID = SiteContext.CurrentSiteID; try { ABVariantInfoProvider.SetABVariantInfo(variantInfo); } catch (InfoObjectException ex) { newDocument.Delete(true, true); ShowError(ex.Message); return(false); } return(true); }
/// <summary> /// Validates the form. If validation succeeds returns true, otherwise returns false. /// </summary> private bool Validate() { // Validate required fields string errorMessage = new Validator() .NotEmpty(txtABVariantDisplayName.Text.Trim(), rfvABVariantDisplayName.ErrorMessage) .NotEmpty(txtABVariantName.Text.Trim(), rfvABVariantName.ErrorMessage) .IsCodeName(txtABVariantName.Text.Trim(), GetString("general.invalidcodename")).Result; string abTestName = string.Empty; string siteName = CMSContext.CurrentSiteName; // Get AB test info object ABTestInfo abti = ABTestInfoProvider.GetABTestInfo(TestID); if (abti != null) { abTestName = abti.ABTestName; } // Test unique codename ABVariantInfo info = ABVariantInfoProvider.GetABVariantInfo(txtABVariantName.Text.Trim(), abTestName, siteName); if ((info != null) && ((VariantObj == null) || (info.ABVariantID != VariantObj.ABVariantID))) { errorMessage = GetString("general.codenameexists"); } if (String.IsNullOrEmpty(ucPath.Value.ToString())) { errorMessage = GetString("abtesting.entertestpage"); } // Set the error message if (!String.IsNullOrEmpty(errorMessage)) { ShowError(errorMessage); return(false); } return(true); }
/// <summary> /// Handles Unigrid's OnAction event. /// </summary> /// <param name="actionName">Name of the action</param> /// <param name="actionArgument">Action argument</param> protected void gridElem_OnAction(string actionName, object actionArgument) { switch (actionName) { case "delete": int variantID = ValidationHelper.GetInteger(actionArgument, 0); if (variantID > 0) { var variant = ABVariantInfoProvider.GetABVariantInfo(variantID); if (variant != null) { if (variant.ABVariantPath != ABTest.ABTestOriginalPage) { ABVariantInfoProvider.DeleteABVariantInfo(variantID); } else { ShowError(GetString("abtesting.deleteoriginalvariant")); } } } break; } }
/// <summary> /// Creates document. /// </summary> /// <param name="createAnother">If false user will be redirected to created document</param> public int Save(bool createAnother) { // Validate input data string message = new Validator().NotEmpty(txtDocumentName.Text.Trim(), GetString("om.enterdocumentname")).Result; if (message == String.Empty) { if (node != null) { // Select parent node TreeNode parent = tree.SelectSingleNode(CMSContext.CurrentSiteName, ucPath.Value.ToString(), TreeProvider.ALL_CULTURES, false, null, false); if (parent != null) { // Check security if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(parent.NodeID, node.NodeClassName)) { RedirectToAccessDenied(GetString("cmsdesk.notauthorizedtocreatedocument")); return(0); } TreeNode newNode = ProcessAction(node, parent, "copynode", false, true, true); if (newNode != null) { newNode.SetValue("DocumentMenuItemHideInNavigation", !chkShowInNavigation.Checked); newNode.SetValue("DocumentShowInSiteMap", chkShowInSiteMap.Checked); newNode.SetValue("DocumentSearchExcluded", chkExcludeFromSearch.Checked); // Limit length to 100 characters string nodeAlias = TextHelper.LimitLength(txtDocumentName.Text.Trim(), 100, String.Empty); newNode.NodeAlias = nodeAlias; newNode.DocumentName = nodeAlias; // Update menu item name newNode.SetDocumentNameSource(nodeAlias); newNode.Update(); // If ABTest selected - create new variant int abTestID = ValidationHelper.GetInteger(ucABTestSelector.Value, 0); if (abTestID != 0) { ABTestInfo abTest = ABTestInfoProvider.GetABTestInfo(abTestID); if (abTest != null) { string defaultCodeName = TextHelper.LimitLength(ValidationHelper.GetCodeName(newNode.GetDocumentName()), 45, String.Empty); string codeName = defaultCodeName; ABVariantInfo info = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, CMSContext.CurrentSiteName); // Find non existing variant code name int index = 0; while (info != null) { index++; codeName = defaultCodeName + "-" + index; info = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, CMSContext.CurrentSiteName); } // Save AB Variant ABVariantInfo variantInfo = new ABVariantInfo(); variantInfo.ABVariantTestID = abTestID; variantInfo.ABVariantPath = newNode.NodeAliasPath; variantInfo.ABVariantName = codeName; variantInfo.ABVariantDisplayName = newNode.GetDocumentName(); variantInfo.ABVariantSiteID = CMSContext.CurrentSiteID; ABVariantInfoProvider.SetABVariantInfo(variantInfo); } } // Get the page mode if (CMSContext.ViewMode != ViewModeEnum.EditLive) { CMSContext.ViewMode = ViewModeEnum.EditForm; } txtDocumentName.Text = String.Empty; return(newNode.NodeID); } } else { message = GetString("om.pathdoesnotexists"); } } } if (message != String.Empty) { lblError.Visible = true; lblError.Text = message; } return(0); }