public List <AirQualityLongTerm> GetCityMonthlyAirQuality(string token, DateTime time, string areaCode)
 {
     if (validator.Validate(token, "CityAirQuality", "GetCityMonthlyAirQuality"))
     {
         IQueryable <CityMonthlyAirQuality> query = model.CityMonthlyAirQuality.Where(o => o.Time == time);
         if (!string.IsNullOrEmpty(areaCode))
         {
             Area area = model.Area.FirstOrDefault(o => o.AreaCode == areaCode);
             if (area == null)
             {
                 query = query.Where(o => false);
             }
             else
             {
                 string[] cityCodes = area.City.Select(o => o.CityCode).ToArray();
                 query = query.Where(o => cityCodes.Contains(o.Code));
             }
         }
         List <AirQualityLongTerm>    list       = query.ToList().Select(o => o.ToAirQualityLongTerm()).ToList();
         AirQualityLongTermCalculator calculator = new AirQualityLongTermCalculator();
         calculator.CalculateRank(list);
         return(list);
     }
     else
     {
         return(null);
     }
 }
 public List <AirQualityLongTerm> GetCityAnyTimeRangeAirQuality(string token, DateTime startTime, DateTime endTime, string areaCode)
 {
     if (validator.Validate(token, "CityAirQuality", "GetCityAnyTimeRangeAirQuality"))
     {
         IQueryable <CityDailyAirQuality> query = model.CityDailyAirQuality.Where(o => o.Time >= startTime && o.Time <= endTime);
         if (!string.IsNullOrEmpty(areaCode))
         {
             Area area = model.Area.FirstOrDefault(o => o.AreaCode == areaCode);
             if (area == null)
             {
                 query = query.Where(o => false);
             }
             else
             {
                 string[] cityCodes = area.City.Select(o => o.CityCode).ToArray();
                 query = query.Where(o => cityCodes.Contains(o.Code));
             }
         }
         List <AirQualityShortTerm>   source     = query.ToList().Select(o => o.ToAirQualityShortTerm()).ToList();
         AirQualityLongTermCalculator calculator = new AirQualityLongTermCalculator();
         List <AirQualityLongTerm>    list       = new List <AirQualityLongTerm>();
         foreach (var cityGroup in source.GroupBy(o => o.Code))
         {
             AirQualityShortTerm first = cityGroup.First();
             AirQualityLongTerm  item  = new AirQualityLongTerm()
             {
                 Code = first.Code,
                 Time = startTime,
                 Name = first.Name
             };
             calculator.Calculate(cityGroup, item);
             list.Add(item);
         }
         calculator.CalculateRank(list);
         return(list);
     }
     else
     {
         return(null);
     }
 }