Пример #1
0
        public Task <IViewComponentResult> InvokeAsync(ISimpleEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(Task.FromResult((IViewComponentResult)View((SimpleEntity)entity)));
        }
Пример #2
0
        // -----------------

        private static IList <T> BuildHierarchyRecursively <T>(
            ILookup <int, ISimpleEntity> input,
            IList <T> output     = null,
            ISimpleEntity parent = null,
            int parentId         = 0,
            int depth            = 0) where T : class, ISimpleEntity
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (output == null)
            {
                output = new List <T>();
            }
            if (parentId == 0)
            {
                depth = 0;
            }

            foreach (var entity in input[parentId])
            {
                var item = (T)entity;
                if (depth < 0)
                {
                    depth = 0;
                }
                if (parent != null)
                {
                    depth++;
                }

                item.Depth  = depth;
                item.Parent = parent;

                if (parent != null)
                {
                    var children = new List <ISimpleEntity>()
                    {
                        item
                    };
                    if (parent.Children != null)
                    {
                        children.AddRange(parent.Children);
                    }

                    parent.Children = children.OrderBy(c => c.SortOrder);
                }

                output.Add(item);

                // recurse
                BuildHierarchyRecursively <T>(input, output, item, item.Id, depth--);
            }

            return(output);
        }
Пример #3
0
        // IComparable

        public int CompareTo(ISimpleEntity other)
        {
            if (other == null)
            {
                return(1);
            }
            var sortOrderCompare = other.SortOrder;

            if (this.SortOrder == sortOrderCompare)
            {
                return(0);
            }
            if (this.SortOrder < sortOrderCompare)
            {
                return(-1);
            }
            if (this.SortOrder > sortOrderCompare)
            {
                return(1);
            }
            return(0);
        }
Пример #4
0
 static bool CaseSensitiveNameSize(ISimpleEntity x, ISimpleEntity y)
 {
     return(string.Equals(x.Name, y.Name, StringComparison.Ordinal) && x.Size == y.Size);
 }
Пример #5
0
 static bool SimpleEntityEqualSize(ISimpleEntity x, ISimpleEntity y)
 {
     return(x.Size == y.Size);
 }