public Tuple <List <BatteryFastDeliveryModel>, int> SelectBatteryFastDelivery(string serviceTypePid, int pageIndex, int pageSize) { int totalCount = 0; List <BatteryFastDeliveryModel> fastDeliveryInfos = null; List <BatteryFastDeliveryProductsModel> batteryList = null; try { fastDeliveryInfos = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.SelectBatteryFastDelivery(conn, serviceTypePid, pageIndex, pageSize, out totalCount)); var fastDeliveryIdsStr = string.Join(",", fastDeliveryInfos.Select(s => s.PKID).ToList()); batteryList = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.GetBatteryFastDeliveryProductsByFastDeliveryId(conn, fastDeliveryIdsStr)); var batteryDic = batteryList.GroupBy(item => item.FastDeliveryId) .ToDictionary(i => i.Key, i => i.ToList().GroupBy(t => t.Brand).ToDictionary(j => j.Key, j => j.Select(s => s.ProductPid).Take(5).ToList())); using (var client = new RegionClient()) { foreach (var fastDeliveryInfo in fastDeliveryInfos) { fastDeliveryInfo.Products = batteryDic.ContainsKey(fastDeliveryInfo.PKID) ? batteryDic[fastDeliveryInfo.PKID] : null; var serviceResult = client.GetSimpleRegionByRegionId(fastDeliveryInfo.RegionId); serviceResult.ThrowIfException(true); if (serviceResult?.Result != null) { fastDeliveryInfo.ProvinceName = serviceResult.Result.ProvinceName; fastDeliveryInfo.CityName = serviceResult.Result.CityName; fastDeliveryInfo.DistrictName = serviceResult.Result.DistrictName; } } return(new Tuple <List <BatteryFastDeliveryModel>, int>(fastDeliveryInfos, totalCount)); } } catch (Exception ex) { Logger.Error("SelectBatteryFastDelivery", ex); return(new Tuple <List <BatteryFastDeliveryModel>, int>(null, 0)); } }