示例#1
0
        public List <SubCategoriesList> GetIncomesFromCategoryGroupedBySubCategoryInRange()
        {
            List <SubCategoriesList> models = new List <SubCategoriesList>();

            var query = from item in AllOperations
                        where !item.isExpense
                        group item by item.Category into g
                        select new {
                Category      = g.Key,
                SubCategories = from stem in g
                                group stem.Cost by stem.CategoryGlobalId into gr
                                orderby gr.Sum() descending
                                select new {
                    SubCategoryId = gr.Key,
                    Cost          = gr.Sum()
                }
            };

            foreach (var item in query)
            {
                if (item.SubCategories.Count() <= 1)
                {
                    continue;
                }

                // Category category = CategoriesDal.GetCategoryByGlobalId(item.CategoryId);

                SubCategoriesList itemList = new SubCategoriesList {
                    Category = item.Category
                };

                decimal groupySum = item.SubCategories.Sum(i => i.Cost);

                foreach (var sitem in item.SubCategories)
                {
                    Category subCategory = _categoriesAndSubCategories.FirstOrDefault(category => category.GlobalId == sitem.SubCategoryId && category is SubCategory);//sitem.SubCategory;

                    if (subCategory != null)
                    {
                        itemList.List.Add(new ChartDataItem(
                                              (double)(sitem.Cost / groupySum),
                                              subCategory.Brush,
                                              subCategory.Name,
                                              (double)sitem.Cost
                                              ));
                    }
                    else
                    {
                        itemList.List.Add(new ChartDataItem(
                                              (double)(sitem.Cost / groupySum),
                                              item.Category.Brush,
                                              "Bez podkategorii",
                                              (double)sitem.Cost
                                              ));
                    }
                }

                models.Add(itemList);
            }

            return(models);
        }
示例#2
0
        public List <SubCategoriesList> GetExpensesFromCategoryGroupedBySubCategoryInRange()
        {
            List <SubCategoriesList> models = new List <SubCategoriesList>();

            var query = from item in AllOperations
                        where item.isExpense
                        group item by item.Category into g
                        select new {
                Category      = g.Key,
                SubCategories = from stem in g
                                group stem.Cost by stem.CategoryGlobalId into gr
                                orderby gr.Sum() descending
                                select new {
                    SubCategoryId = gr.Key,
                    Cost          = gr.Sum()
                }
            };

            foreach (var item in query)
            {
                if (item.SubCategories.Count() <= 1)
                {
                    continue;
                }

                //     Category category = CategoriesDal.GetCategoryByGlobalId(item.CategoryId);

                SubCategoriesList itemList = new SubCategoriesList {
                    Category = item.Category
                };

                decimal groupySum = item.SubCategories.Sum(i => i.Cost);

                /*
                 * var subCategories = item.SubCategories.Where(i => i.Cost / groupySum > (decimal) 0.01);
                 * groupySum = subCategories.Sum(i => i.Cost);
                 */
                foreach (var sitem in item.SubCategories)
                {
                    Category subCategory = _categoriesAndSubCategories.FirstOrDefault(category => category.GlobalId == sitem.SubCategoryId && category is SubCategory);// sitem.SubCategory;//CategoriesDal.GetCategoryByGlobalId(sitem.SubCategoryId);

                    if (subCategory != null)
                    {
                        itemList.List.Add(new ChartDataItem(
                                              (double)(sitem.Cost / groupySum),
                                              subCategory.Brush,
                                              subCategory.Name,
                                              (double)sitem.Cost
                                              ));
                    }
                    else
                    {
                        itemList.List.Add(new ChartDataItem(
                                              (double)(sitem.Cost / groupySum),
                                              item.Category.Brush,
                                              new Windows.ApplicationModel.Resources.ResourceLoader().GetString("withoutSubCategory"),
                                              (double)sitem.Cost
                                              ));
                    }
                }

                models.Add(itemList);
            }

            return(models);
        }