Beispiel #1
0
        public async Task <CdmaRegionDateView> QueryLastDateStat(DateTime initialDate, string city)
        {
            var beginDate = initialDate.AddDays(-100);
            var endDate   = initialDate.AddDays(1);
            var query     = await _statRepository.GetAllListAsync(beginDate, endDate);

            var regions
                = (await _regionRepository.GetAllListAsync(city)).Select(x => x.Region).Distinct().OrderBy(x => x);
            var result = (from q in query
                          join r in regions
                          on q.Region equals r
                          select q).ToList();

            if (result.Count == 0)
            {
                return(null);
            }
            var maxDate  = result.Max(x => x.StatDate);
            var stats    = result.Where(x => x.StatDate == maxDate).ToList();
            var cityStat = stats.ArraySum();

            cityStat.Region = city;
            stats.Add(cityStat);
            return(new CdmaRegionDateView
            {
                StatDate = maxDate,
                StatViews = Mapper.Map <List <CdmaRegionStat>, List <CdmaRegionStatView> >(stats)
            });
        }