コード例 #1
0
        public async Task <IActionResult> MatchStores([FromBody] StoreMatchQuery matchQuery)
        {
            var stores = await _storeService.GetAllStoresAsync(new StoreFilterParams
            {
                ProductsInStock = matchQuery.ProductsInStock
            });

            var stocks = await _storeService.GetStocksAsync(matchQuery.ProductsInStock);

            var nearestZipPairs = await _distanceService.GetNearestZipCodes(matchQuery.NearestStoreFromZip, stores.Select(x => x.ZipCode).ToArray());

            //merge stores
            var nearestStore = (from d in stores
                                join p in nearestZipPairs on d.ZipCode equals p.PostalCode
                                orderby p.DistanceInMeter
                                select new EntityDistanceInfo <StoreDto>
            {
                Entity = d,
                DistanceFromSourceInMeter = p.DistanceInMeter
            }).ToArray();

            var aa = (from d in nearestStore
                      join p in stocks on d.Entity.StoreId equals p.StoreId
                      where matchQuery.ProductsInStock.Contains(p.ProductId) && p.Quantity > 0
                      select new MatchTuple <EntityDistanceInfo <StoreDto>, int>
            {
                Entity = d,
                Association = p.ProductId
            }).ToArray().OrderBy(x => x.Association);

            return(Ok(new Response <IEnumerable <MatchTuple <EntityDistanceInfo <StoreDto>, int> > >(aa)));
        }
コード例 #2
0
ファイル: StoreClient.cs プロジェクト: PhantomCloak/efurni
        public async Task <IEnumerable <MatchTuple <EntityDistanceInfo <StoreDto>, int> > > GetNearestStores(string zipCode, int[] productIds)
        {
            var nearStoreReq = new RestRequest(ApiRoutes.StoreAlias.StoreMatch, Method.POST);

            var aa = new StoreMatchQuery
            {
                NearestStoreFromZip = zipCode,
                ProductsInStock     = productIds
            };

            nearStoreReq.AddJsonBody(aa);

            var response = await _client.ExecuteAsync <Response <IEnumerable <MatchTuple <EntityDistanceInfo <StoreDto>, int> > > >(nearStoreReq);

            return(response.Data.Data);
        }