コード例 #1
0
        protected virtual async Task <FulfillmentSchedule[]> GetStoreSchedules(
            List <Overture.ServiceModel.Customers.Stores.Store> stores, GetStoreLocatorViewModelParam param)
        {
            var getSchedulesTasks = stores.Where(s => s.StoreSchedule == null).Select(s =>
                                                                                      StoreRepository.GetStoreScheduleAsync(new GetStoreScheduleParam
            {
                Scope                 = param.Scope,
                CultureInfo           = param.CultureInfo,
                FulfillmentLocationId = s.FulfillmentLocation.Id
            }));

            return(await Task.WhenAll(getSchedulesTasks).ConfigureAwait(false));
        }
コード例 #2
0
        public void WHEN_ParamsProperty_Is_Null_SHOULD_Throw_Argument_Exception(string scope, string baseUrl)
        {
            //Arrange
            var service = _container.CreateInstance <StoreLocatorViewService>();
            var param   = new GetStoreLocatorViewModelParam
            {
                Scope       = scope,
                BaseUrl     = baseUrl,
                CultureInfo = CultureInfo.CreateSpecificCulture("en-CA")
            };

            //Act
            Func <Task> asyncFunction = async() => { await service.GetStoreLocatorViewModelAsync(param); };

            //Assert
            asyncFunction.ShouldThrow <ArgumentException>();
        }
コード例 #3
0
        protected virtual List <StoreClusterViewModel> GetMarkers(GetStoreLocatorViewModelParam param,
                                                                  List <Overture.ServiceModel.Customers.Stores.Store> stores, Dictionary <string, int> storeIndexes)
        {
            var getClusterParams = new GetMapClustersParam
            {
                ZoomLevel   = param.ZoomLevel,
                SearchPoint = param.SearchPoint,
                Locations   = stores.Select(s => new StoreGeoCoordinate(s)).Cast <IGeoCoordinate>().ToList()
            };
            var clusters = MapClustererProvider.GetMapClusters(getClusterParams);

            return(clusters.Select(c =>
                                   new StoreClusterViewModel
            {
                Center = c.Center,
                Tile = c.Tile,
                ItemsCount = c.ItemsCount,
                StoreNumber = c.StoreNumber,
                SearchIndex = c.ItemsCount == 1 ? storeIndexes[c.StoreNumber] : 0
            }).ToList());
        }
コード例 #4
0
        public virtual async Task <StoreLocatorViewModel> GetStoreLocatorViewModelAsync(GetStoreLocatorViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.BaseUrl))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BaseUrl)), nameof(param));
            }

            var overtureStores = await StoreRepository.GetStoresAsync(new GetStoresParam
            {
                Scope            = param.Scope,
                IncludeExtraInfo = true,
                CultureInfo      = param.CultureInfo
            }).ConfigureAwait(false);

            var model = GetEmptyStoreLocatorViewModel(new GetEmptyStoreLocatorViewModelParam
            {
                BaseUrl     = param.BaseUrl,
                CultureInfo = param.CultureInfo
            });

            IEnumerable <Overture.ServiceModel.Customers.Stores.Store> stores = overtureStores.Results;

            if (stores == null || !stores.Any())
            {
                return(model);
            }

            var index = 1;

            //Select the closest store coordinate from all available stores before map InBounds filtering
            if (param.IncludeNearestStoreCoordinate && param.SearchPoint != null)
            {
                var closestStore    = stores.First();
                var closestDistance = closestStore.CalculateDestination(param.SearchPoint, GoogleSettings.LengthMeasureUnit);
                foreach (var currentStore in stores)
                {
                    var currentDistance = currentStore.CalculateDestination(param.SearchPoint, GoogleSettings.LengthMeasureUnit);
                    if (currentDistance < closestDistance)
                    {
                        closestStore    = currentStore;
                        closestDistance = currentDistance;
                    }
                }
                if (closestDistance <= (double)GoogleSettings.StoresAvailabilityDistance)
                {
                    model.NearestDistance        = closestDistance;
                    model.LengthMeasureUnit      = GoogleSettings.LengthMeasureUnit.ToString();
                    model.NearestStoreCoordinate = new StoreGeoCoordinate(closestStore);
                }
            }

            //Inbound filtering
            if (param.MapBounds != null)
            {
                stores = stores.Where(st => st.InBounds(param.MapBounds));
            }

            //Affect next filtering and ordering to the filtered by map bounds result
            if (param.SearchPoint != null)
            {
                stores = stores.FilterSortStoresByDistanceToCustomer(GoogleSettings, param.SearchPoint);
            }

            if (!stores.Any())
            {
                return(model);
            }
            var storeIndexes = stores.ToDictionary(d => d.Number, d => index++);

            var storesForCurrentPage = stores.Skip((param.PageNumber - 1) * param.PageSize).Take(param.PageSize).ToList();

            var schedules = await GetStoreSchedules(storesForCurrentPage, param);

            foreach (var store in storesForCurrentPage)
            {
                if (store.StoreSchedule == null)
                {
                    store.StoreSchedule = schedules.FirstOrDefault(
                        s => s.FulfillmentLocationId == store.FulfillmentLocation.Id.ToString());
                }

                var vm = StoreViewModelFactory.CreateStoreViewModel(new CreateStoreViewModelParam
                {
                    Store       = store,
                    CultureInfo = param.CultureInfo,
                    BaseUrl     = param.BaseUrl,
                    SearchPoint = param.SearchPoint
                });

                vm.SearchIndex = storeIndexes[store.Number];

                model.Stores.Add(vm);
            }

            if (param.IncludeMarkers)
            {
                model.Markers = GetMarkers(param, stores.ToList(), storeIndexes);
            }

            model.NextPage = StoreViewModelFactory.BuildNextPage(new GetStorePageViewModelParam
            {
                Total             = stores.Count(),
                PageSize          = param.PageSize,
                CurrentPageNumber = param.PageNumber
            });

            return(model);
        }
コード例 #5
0
        public virtual async Task <StoreLocatorViewModel> GetStoreLocatorViewModelAsync(GetStoreLocatorViewModelParam viewModelParam)
        {
            if (viewModelParam == null)
            {
                throw new ArgumentNullException("param");
            }
            if (string.IsNullOrWhiteSpace(viewModelParam.Scope))
            {
                throw new ArgumentNullException("scope");
            }
            if (viewModelParam.CultureInfo == null)
            {
                throw new ArgumentNullException("cultureInfo");
            }
            if (string.IsNullOrWhiteSpace(viewModelParam.BaseUrl))
            {
                throw new ArgumentNullException("baseUrl");
            }

            var overtureStores =
                await
                StoreRepository.GetStoresAsync(new GetStoresParam { Scope = viewModelParam.Scope, IncludeExtraInfo = true })
                .ConfigureAwait(false);

            var model =
                GetEmptyStoreLocatorViewModel(new GetEmptyStoreLocatorViewModelParam
            {
                BaseUrl     = viewModelParam.BaseUrl,
                CultureInfo = viewModelParam.CultureInfo
            });

            var stores = overtureStores.Results;

            var index = 1;

            if (viewModelParam.SearchPoint != null)
            {
                stores = stores.OrderBy(s => s.CalculateDestination(viewModelParam.SearchPoint)).ToList();
                model.NearestStoreCoordinate = new StoreGeoCoordinate(stores.FirstOrDefault());
            }
            var storeIndexes = stores.ToDictionary(d => d.Number, d => index++);

            if (viewModelParam.MapBounds != null)
            {
                stores = stores.Where(st => st.InBounds(viewModelParam.MapBounds)).ToList();
            }

            var storesForCurrentPage =
                stores.Skip((viewModelParam.PageNumber - 1) * viewModelParam.PageSize)
                .Take(viewModelParam.PageSize)
                .ToList();


            var schedules = await GetStoreSchedules(storesForCurrentPage, viewModelParam);

            foreach (var store in storesForCurrentPage)
            {
                if (store.StoreSchedule == null)
                {
                    store.StoreSchedule =
                        schedules.FirstOrDefault(s => s.FulfillmentLocationId == store.FulfillmentLocation.Id.ToString());
                }
                var vm = StoreViewModelFactory.CreateStoreViewModel(new CreateStoreViewModelParam
                {
                    Store       = store,
                    CultureInfo = viewModelParam.CultureInfo,
                    BaseUrl     = viewModelParam.BaseUrl,
                    SearchPoint = viewModelParam.SearchPoint
                });

                vm.SearchIndex = storeIndexes[store.Number];

                model.Stores.Add(vm);
            }

            if (viewModelParam.IncludeMarkers)
            {
                model.Markers = GetMarkers(viewModelParam, stores, storeIndexes);
            }

            model.NextPage = StoreViewModelFactory.BuildNextPage(new GetStorePageViewModelParam
            {
                Total             = stores.Count,
                PageSize          = viewModelParam.PageSize,
                CurrentPageNumber = viewModelParam.PageNumber
            });

            return(model);
        }