public virtual async Task <List <StoreViewModel> > GetStoresForInStorePickupViewModelAsync(GetStoresForInStorePickupViewModelParam param) { var getStoresParam = new GetStoresParam { BaseUrl = param.BaseUrl, CultureInfo = param.CultureInfo, Scope = param.Scope }; var stores = await StoreRepository.GetStoresAsync(getStoresParam).ConfigureAwait(false); if (stores.Results != null) { var vm = stores.Results .Where(s => s.IsActive && s.FulfillmentLocation != null && s.FulfillmentLocation.IsPickUpLocation) .Select(s => StoreViewModelFactory.CreateStoreViewModel(new CreateStoreViewModelParam { BaseUrl = param.BaseUrl, CultureInfo = param.CultureInfo, Store = s })).ToList(); return(vm); } return(new List <StoreViewModel>()); }
public virtual async Task <List <StoreViewModel> > GetAllStoresViewModelAsync(GetStoresParam param) { var overtureStores = await StoreRepository.GetStoresAsync(param).ConfigureAwait(false); IEnumerable <Overture.ServiceModel.Customers.Stores.Store> stores = overtureStores.Results; if (stores == null) { return(new List <StoreViewModel>()); } stores = stores.Where(s => s.IsActive && s.FulfillmentLocation != null && s.FulfillmentLocation.IsActive); if (param.SearchPoint != null) { stores = stores.FilterSortStoresByDistanceToCustomer(GoogleSettings, param.SearchPoint); } var vm = stores.Select(s => StoreViewModelFactory.CreateStoreViewModel(new CreateStoreViewModelParam { BaseUrl = param.BaseUrl, CultureInfo = param.CultureInfo, Store = s, SearchPoint = param.SearchPoint })).ToList(); return(vm); }
public virtual async Task <StoreDirectoryViewModel> GetStoreDirectoryViewModelAsync(GetStoresParam viewModelParam) { if (string.IsNullOrWhiteSpace(viewModelParam.Scope)) { throw new ArgumentException("scope"); } if (viewModelParam.CultureInfo == null) { throw new ArgumentNullException("cultureInfo"); } if (string.IsNullOrWhiteSpace(viewModelParam.BaseUrl)) { throw new ArgumentException("baseUrl"); } var model = new StoreDirectoryViewModel(); model.StoreLocatorPageUrl = StoreUrlProvider.GetStoreLocatorUrl(new GetStoreLocatorUrlParam { BaseUrl = viewModelParam.BaseUrl, CultureInfo = viewModelParam.CultureInfo, Page = 1 }); var overtureStores = await StoreRepository.GetStoresAsync(new GetStoresParam { CultureInfo = viewModelParam.CultureInfo, Scope = viewModelParam.Scope, PageNumber = 1, PageSize = int.MaxValue }).ConfigureAwait(false); var sortedResults = SortStoreDirectoryResult(overtureStores.Results); //get result for currect page var totalCount = sortedResults.Count(); var result = sortedResults.Skip((viewModelParam.PageNumber - 1) * viewModelParam.PageSize) .Take(viewModelParam.PageSize).OrderBy(st => st.Name).ToList(); var stores = result.Select(it => StoreViewModelFactory.CreateStoreViewModel(new CreateStoreViewModelParam { Store = it, CultureInfo = viewModelParam.CultureInfo, BaseUrl = viewModelParam.BaseUrl })).ToList(); model.Pagination = BuildPagination(totalCount, viewModelParam); model.Groups = await GetStoreDirectoryGroupsAsync(stores, viewModelParam); foreach (var countryGroup in model.Groups) { countryGroup.Anchors = await GetStoreDirectoryCountryGroupAnchorsAsync(sortedResults, countryGroup, viewModelParam); } return(model); }
public virtual async Task <StoreViewModel> GetStoreViewModelAsync(GetStoreParam param) { if (param == null) { throw new ArgumentNullException("param"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentNullException("scope"); } if (param.CultureInfo == null) { throw new ArgumentNullException("cultureInfo"); } if (string.IsNullOrWhiteSpace(param.StoreNumber)) { throw new ArgumentNullException("storeNumber"); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentNullException("baseUrl"); } var overtureStore = await StoreRepository.GetStoreByNumberAsync(param).ConfigureAwait(false); if (overtureStore == null) { return(null); } var createVmParam = new CreateStoreViewModelParam { Store = overtureStore, CultureInfo = param.CultureInfo, BaseUrl = param.BaseUrl, SearchPoint = param.SearchPoint }; var storeViewModel = StoreViewModelFactory.CreateStoreViewModel(createVmParam); storeViewModel.StructuredData = StoreViewModelFactory.CreateStoreStructuredDataViewModel(createVmParam); if (storeViewModel.HasLocation()) { storeViewModel.Context.Add("latitude", storeViewModel.GetLatitude().ToString(CultureInfo.InvariantCulture)); storeViewModel.Context.Add("longitude", storeViewModel.GetLongitude().ToString(CultureInfo.InvariantCulture)); } return(storeViewModel); }
public virtual async Task <StoreInventoryViewModel> GetStoreInventoryViewModelAsync(GetStoreInventoryViewModelParam 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)); } if (string.IsNullOrWhiteSpace(param.Sku)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Sku)), nameof(param)); } var overtureInventoryItems = await InventoryRepository.GetInventoryItemsBySkuAsync(new GetInventoryItemsBySkuParam { Scope = param.Scope, Sku = param.Sku, Date = param.Date, IncludeChildScopes = true }).ConfigureAwait(false); if (overtureInventoryItems == null) { return(null); } var model = new StoreInventoryViewModel { Stores = new List <StoreViewModel>() }; var stores = await GetStores(param, overtureInventoryItems); if (stores.Count == 0) { return(null); } var index = 1; if (param.SearchPoint != null) { stores = stores.OrderBy(s => s.CalculateDestination(param.SearchPoint)).ToList(); } var storeIndexes = stores.ToDictionary(d => d.Number, d => index++); var storesForCurrentPage = stores.Skip((param.PageNumber - 1) * param.PageSize) .Take(param.PageSize) .ToList(); var isInventoryEnabled = await IsInventoryEnabledAsync(param); var statusDisplayNames = await GetInventoryStatusDisplayNamesAsync(param, isInventoryEnabled); foreach (var store in storesForCurrentPage) { var vm = StoreViewModelFactory.CreateStoreViewModel(new CreateStoreViewModelParam { Store = store, CultureInfo = param.CultureInfo, BaseUrl = param.BaseUrl, SearchPoint = param.SearchPoint }); vm.SearchIndex = storeIndexes[store.Number]; var inventory = overtureInventoryItems.Results.FirstOrDefault(inv => inv.FulfillmentLocationNumber == store.Number); if (inventory != null) { vm.InventoryStatus = GetInventoryStatusViewModel(isInventoryEnabled, inventory, statusDisplayNames); } model.Stores.Add(vm); } model.NextPage = StoreViewModelFactory.BuildNextPage(new GetStorePageViewModelParam { Total = stores.Count, PageSize = param.PageSize, CurrentPageNumber = param.PageNumber }); return(model); }
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); }
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); }