예제 #1
0
        /// <summary>
        /// 查询覆盖区域
        /// </summary>
        /// <param name="brand"></param>
        /// <param name="province"></param>
        /// <param name="city"></param>
        /// <param name="district"></param>
        /// <param name="pager"></param>
        /// <returns></returns>
        public async Task <Tuple <List <VendorProductCoverAreaViewModel>, int> > SelectVendorProductCoverArea
            (string productType, string coverType, string brand, string pid,
            int provinceId, int cityId, int districtId, PagerModel pager)
        {
            var result     = new List <VendorProductCoverAreaViewModel>();
            var totalCount = 0;

            try
            {
                var regionIds = await GetDistrictIdsByRegionAsync(provinceId, cityId, districtId);

                var searchResult = null as Tuple <List <VendorProductCoverAreaModel>, int>;
                switch (coverType)
                {
                case "Brand":
                    searchResult = _dbScopeManagerConfigRead.Execute(conn =>
                                                                     _dal.SearchVendorProductCoverArea(conn, productType, coverType, brand, null, regionIds, pager)); break;

                case "Pid":
                    searchResult = _dbScopeManagerConfigRead.Execute(conn =>
                                                                     _dal.SearchVendorProductCoverArea(conn, productType, coverType, null, pid, regionIds, pager)); break;

                default: break;
                }
                var configs = searchResult?.Item1;
                totalCount = searchResult?.Item2 ?? 0;
                var regions = await _regionService.GetAllDistrictsFromCache();

                configs?.ForEach(s =>
                {
                    var district = regions.FirstOrDefault(r => r.DistrictId == s.CoverRegionId);
                    if (district != null)
                    {
                        result.Add(new VendorProductCoverAreaViewModel()
                        {
                            Brand              = s.Brand,
                            CityId             = district.CityId,
                            CityName           = district.CityName,
                            CoverRegionId      = s.CoverRegionId,
                            CoverType          = s.CoverType,
                            CreateDateTime     = s.CreateDateTime,
                            DistrictId         = district.DistrictId,
                            DistrictName       = district.DistrictName,
                            IsDeleted          = s.IsDeleted,
                            IsEnabled          = s.IsEnabled,
                            LastUpdateDateTime = s.LastUpdateDateTime,
                            Pid          = s.Pid,
                            PKID         = s.PKID,
                            ProductType  = s.ProductType,
                            ProvinceId   = district.ProvinceId,
                            ProvinceName = district.ProvinceName,
                            Remark       = s.Remark
                        });
                    }
                });
            }
            catch (Exception ex)
            {
                _logger.Error("SearchCoverArea", ex);
                result = null;
            }
            return(Tuple.Create(result, totalCount));
        }