Example #1
0
        private void BuildTree()
        {
            if (allCategories.Count() == 0)
            {
                return;
            }

            Root = new CategoryTreeNode(allCategories.First(x => x.Id == rootCategoryId));
            BuildTree(Root);
        }
Example #2
0
        private void BuildTree(CategoryTreeNode parent)
        {
            var catChilds = allCategories.Where(x => x.ParentCategoryId == parent.Value.Id).ToList();

            if (catChilds.Count > 0)
            {
                parent.Childs = new List <CategoryTreeNode>();
            }

            foreach (var child in catChilds)
            {
                parent.Childs.Add(new CategoryTreeNode(child));
                BuildTree(parent.Childs.Last());
            }
        }
Example #3
0
        public List <Categories> ToList(CategoryTreeNode node)
        {
            List <Categories> result = new List <Categories>();

            result.Add(node.Value);

            if (node.Childs != null)
            {
                foreach (var item in node.Childs)
                {
                    result.AddRange(ToList(item));
                }
            }

            return(result);
        }
        public CategorySummary(CategoryTreeNode root, List<Expenses> expenses)
        {
            Category = root.Value;
            ExpensesCost = expenses.Sum(x => x.TotalPrice);

            decimal catCostSum = expenses.Where(x => x.CategoryId == root.Value.Id).Sum(x => x.TotalPrice);
            TryAddSummaryItem(catCostSum, root.Value.Name);

            if (root.Childs != null)
            {
                foreach (var child in root.Childs)
                {
                    List<int> childAndSubchildsCatIds = child.ToList().Select(x => x.Id).ToList();
                    catCostSum = expenses.Where(x => childAndSubchildsCatIds.Contains(x.CategoryId)).Sum(x => x.TotalPrice);

                    TryAddSummaryItem(catCostSum, child.Value.Name);
                }
            }

            SummaryItems = SummaryItems.OrderByDescending(x => x.Value).ToList();
            CalculatePercentages();
        }