示例#1
0
        private static List <ForumSorted> SortList(
            this IRepository <Forum> repository,
            [NotNull] List <Tuple <Forum, Category, ActiveAccess> > listSource,
            [NotNull] int parentId,
            [NotNull] int categoryId,
            [NotNull] int startingIndent,
            [NotNull] bool emptyFirstRow)
        {
            CodeContracts.VerifyNotNull(repository);

            var listDestination = new List <ForumSorted>();

            if (emptyFirstRow)
            {
                var blankRow = new ForumSorted
                {
                    ForumID  = 0,
                    Forum    = BoardContext.Current.Get <ILocalization>().GetText("NONE"),
                    Category = string.Empty,
                    Icon     = string.Empty
                };

                listDestination.Add(blankRow);
            }

            repository.SortListRecursive(listSource, listDestination, parentId, categoryId, startingIndent);

            return(listDestination);
        }
示例#2
0
        /// <summary>
        /// The SortListRecursive.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="listSource">
        /// The list source.
        /// </param>
        /// <param name="listDestination">
        /// The list destination.
        /// </param>
        /// <param name="parentID">
        /// The parent id.
        /// </param>
        /// <param name="categoryID">
        /// The category id.
        /// </param>
        /// <param name="currentIndent">
        /// The current indent.
        /// </param>
        private static void SortListRecursive(
            this IRepository <Forum> repository,
            [NotNull] List <Tuple <Forum, Category, ActiveAccess> > listSource,
            [NotNull] ICollection <ForumSorted> listDestination,
            [NotNull] int parentId,
            [NotNull] int categoryId,
            [NotNull] int currentIndent)
        {
            CodeContracts.VerifyNotNull(repository);

            foreach (var(item1, item2, _) in listSource)
            {
                // see if this is a root-forum
                item1.ParentID ??= 0;

                if (item1.ParentID != parentId)
                {
                    continue;
                }

                if (item2.ID != categoryId)
                {
                    categoryId = item2.ID;

                    listDestination.Add(
                        new ForumSorted
                    {
                        ForumID  = -categoryId,
                        Forum    = $"{item2.Name}",
                        Category = $"{item2.Name}",
                        Icon     = "folder"
                    });
                }

                var indent = string.Empty;

                for (var j = 0; j < currentIndent; j++)
                {
                    indent += "-";
                }

                // import the row into the destination
                var newRow = new ForumSorted
                {
                    ForumID  = item1.ID,
                    Forum    = $" {indent} {item1.Name}",
                    Category = $"{item2.Name}",
                    Icon     = "comments"
                };


                listDestination.Add(newRow);

                // recurse through the list...
                repository.SortListRecursive(listSource, listDestination, item1.ID, categoryId, currentIndent + 1);
            }
        }
示例#3
0
        /// <summary>
        /// The SortListRecursive.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="listSource">
        /// The list source.
        /// </param>
        /// <param name="listDestination">
        /// The list destination.
        /// </param>
        /// <param name="parentId">
        /// The parent id.
        /// </param>
        /// <param name="currentIndent">
        /// The current indent.
        /// </param>
        private static void SortListRecursive(
            this IRepository <Forum> repository,
            [NotNull] List <Forum> listSource,
            [NotNull] ICollection <ForumSorted> listDestination,
            [NotNull] int parentId,
            [NotNull] int currentIndent)
        {
            listSource.ForEach(
                forum =>
            {
                // see if this is a root-forum
                forum.ParentID ??= 0;

                if (forum.ParentID != parentId)
                {
                    return;
                }

                var indent = string.Empty;

                for (var j = 0; j < currentIndent; j++)
                {
                    indent += "--";
                }

                // import the row into the destination
                var newRow = new ForumSorted
                {
                    ForumID = forum.ID, Forum = $" -{indent} {forum.Name}", Icon = "comments"
                };

                listDestination.Add(newRow);

                // recurse through the list...
                repository.SortListRecursive(listSource, listDestination, forum.ID, currentIndent + 1);
            });
        }