Exemple #1
0
    protected void variantDailog_OnDeleteVariant(object sender, EventArgs e)
    {
        if (Variants.Count <= 0)
        {
            return;
        }

        // Allow modifying issues in idle state only
        IssueInfo parentIssue = IssueInfoProvider.GetOriginalIssue(IssueID);

        if ((parentIssue == null) || (parentIssue.IssueStatus != IssueStatusEnum.Idle))
        {
            return;
        }

        int currVariant = CurrentVariant;

        if (Variants.Count > 2)
        {
            IssueInfoProvider.DeleteIssueInfo(Variants[currVariant].IssueID);
            Variants.RemoveAt(currVariant);
            RaiseVariantDeleted();
        }
        else
        {
            if (Variants.Count == 2)
            {
                // Remove variant
                IssueInfoProvider.DeleteIssueInfo(Variants[currVariant].IssueID);
                Variants.RemoveAt(currVariant);
            }

            // Get remaining variant
            IssueABVariantItem issueVariant = Variants[0];
            Variants.Clear();
            IssueInfo issue = IssueInfoProvider.GetIssueInfo(issueVariant.IssueID);
            if (issue != null)
            {
                // Transfer all data from child to parent and delete child
                const string ignoredColumns = ";issueid;issueguid;issuevariantname;";
                foreach (string column in parentIssue.ColumnNames)
                {
                    if (!ignoredColumns.Contains(String.Format(";{0};", column.ToLowerCSafe())))
                    {
                        parentIssue.SetValue(column, issue.GetValue(column));
                    }
                }
                parentIssue.IssueIsABTest         = false;
                parentIssue.IssueVariantName      = null;
                parentIssue.IssueVariantOfIssueID = 0;
                IssueInfoProvider.SetIssueInfo(parentIssue);

                // Delete files from parent issue if any
                MetaFileInfoProvider.DeleteFiles(parentIssue.IssueID, IssueInfo.OBJECT_TYPE, ObjectAttachmentsCategories.ISSUE);
                MetaFileInfoProvider.DeleteFiles(parentIssue.IssueID, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE);

                // Move attachments (meta files) from child to parent
                MetaFileInfoProvider.MoveMetaFiles(issue.IssueID, parentIssue.IssueID, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE, ObjectAttachmentsCategories.ISSUE);
                MetaFileInfoProvider.MoveMetaFiles(issue.IssueID, parentIssue.IssueID, IssueInfo.OBJECT_TYPE, ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE, ObjectAttachmentsCategories.ISSUE);

                // Delete last variant
                IssueInfoProvider.DeleteIssueInfo(issue);
                OriginalIssueID = parentIssue.IssueID;

                // A/B variants have been deleted => deleting A/B test itself
                ABTestInfo abi = ABTestInfoProvider.GetABTestInfoForIssue(OriginalIssueID);
                ABTestInfoProvider.DeleteABTestInfo(abi);
            }
            RaiseVariantDeleted();
        }
    }