Example #1
0
        public async Task <Dictionary <int, int> > GetCategoryCountAsync(List <Battery> batteries, List <Category> categories)
        {
            Dictionary <int, int> categoryCounts = new();

            foreach (var battery in batteries)
            {
                var charges = await _chargeService.GetActiveParentsAndChildrenAsync(battery);

                foreach (var category in categories.Where(x => x.BatteryId == battery.Id).ToList())
                {
                    var chargeCatCount = charges.Where(x => x.CategoryId == category.Id)
                                         .Count();

                    categoryCounts.Add(category.Id, chargeCatCount);
                }
            }

            return(categoryCounts);
        }
Example #2
0
        public async Task <Dictionary <int, int> > CountActiveChargeTagRelationshipsAsync(Battery battery)
        {
            Dictionary <int, int> counts = new();
            var tags = await _tagService.GetAsync(battery);

            var combinedCharges = await _chargeService.GetActiveParentsAndChildrenAsync(battery);

            foreach (var tag in tags)
            {
                var relations = await _chargeTagRelationService.GetAllRelationsForTagAsync(tag.Id);

                var relationsCount = (from c in combinedCharges
                                      join r in relations on c.Id equals r.ChargeId
                                      select r
                                      ).Count();

                counts.Add(tag.Id, relationsCount);
            }

            return(counts);
        }