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 <FindStoresQueryResult> GetStoresAsync(GetStoresParam getStoresParam) { if (string.IsNullOrWhiteSpace(getStoresParam.Scope)) { throw new ArgumentException("scope"); } var cacheKey = new CacheKey(CacheConfigurationCategoryNames.Store) { Scope = getStoresParam.Scope }; cacheKey.AppendKeyParts(GETSTORES_CACHE_KEYPART); var request = new FindStoresRequest { ScopeId = getStoresParam.Scope, Query = new Query { StartingIndex = 0, MaximumItems = int.MaxValue, IncludeTotalCount = false, Filter = new FilterGroup { Filters = GetStoreFilters() } } }; var stores = await CacheProvider.GetOrAddAsync(cacheKey, () => OvertureClient.SendAsync(request)) .ConfigureAwait(false); // TODO: Remove this as soon as the FindStoresRequest returns localized display names. if (stores.Results.Any(s => s.DisplayName != null)) { return(stores); } // Try get DisplayNames if (getStoresParam.IncludeExtraInfo) { var ids = stores.Results.Select(x => x.Id).ToList(); var extraStoresInfo = await GetExtraStoresInfoAsync(ids, getStoresParam).ConfigureAwait(false); for (var index = 0; index < stores.Results.Count; index++) { var store = stores.Results[index]; var extraInfo = extraStoresInfo[index]; object displayName = null; extraInfo?.PropertyBag.TryGetValue("DisplayName", out displayName); if (displayName != null) { store.DisplayName = displayName as Overture.ServiceModel.LocalizedString; } } } return(stores); }
protected virtual StorePaginationViewModel BuildPagination(int totalCount, GetStoresParam param) { StorePageViewModel prevPage = null, nextPage = null; if (param.PageSize * param.PageNumber < totalCount) { nextPage = new StorePageViewModel { DisplayName = LocalizationProvider.GetLocalizedString(new GetLocalizedParam { Category = "Store", Key = "B_PaginationNext", CultureInfo = param.CultureInfo }), Url = StoreUrlProvider.GetStoresDirectoryUrl(new GetStoresDirectoryUrlParam { BaseUrl = param.BaseUrl, CultureInfo = param.CultureInfo, Page = param.PageNumber + 1 }) }; } if (param.PageNumber > 1) { prevPage = new StorePageViewModel { DisplayName = LocalizationProvider.GetLocalizedString(new GetLocalizedParam { Category = "Store", Key = "B_PaginationPrev", CultureInfo = param.CultureInfo }), Url = StoreUrlProvider.GetStoresDirectoryUrl(new GetStoresDirectoryUrlParam { BaseUrl = param.BaseUrl, CultureInfo = param.CultureInfo, Page = param.PageNumber - 1 }) }; } var pager = new StorePaginationViewModel { PreviousPage = prevPage, NextPage = nextPage }; return(pager); }
protected virtual async Task <List <StoreDirectoryAnchorViewModel> > GetStoreDirectoryCountryGroupAnchorsAsync( IList <Overture.ServiceModel.Customers.Stores.Store> stores, StoreDirectoryGroupViewModel countryGroup, GetStoresParam viewModelParam) { var countryCode = countryGroup.Key.ToString(); var anchors = new SortedDictionary <string, StoreDirectoryAnchorViewModel>(); int ind = 0; foreach (var store in stores) { ind++; var region = store.FulfillmentLocation.Addresses[0].RegionCode; if (store.FulfillmentLocation.Addresses[0].CountryCode != countryCode || anchors.Keys.Contains(region)) { continue; } var pageNumber = GetTotalPages(ind, viewModelParam.PageSize); anchors.Add(region, new StoreDirectoryAnchorViewModel { DisplayName = await CountryService.RetrieveRegionDisplayNameAsync(new RetrieveRegionDisplayNameParam { CultureInfo = viewModelParam.CultureInfo, IsoCode = countryCode, RegionCode = region }), Key = "#" + region, Url = pageNumber == viewModelParam.PageNumber ? string.Empty : StoreUrlProvider.GetStoresDirectoryUrl(new GetStoresDirectoryUrlParam { BaseUrl = viewModelParam.BaseUrl, CultureInfo = viewModelParam.CultureInfo, Page = pageNumber }) }); } return(anchors.Values.ToList()); }
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); }
protected async virtual Task <List <StoreDirectoryGroupViewModel> > GetStoreDirectoryGroupsAsync(IList <StoreViewModel> stores, GetStoresParam viewModelParam) { var groups = StoreDirectoryGroupByMany(stores, st => st.Address.CountryCode, st => st.Address.RegionCode, st => st.Address.City).ToList(); foreach (var countryGroup in groups) { var countryCode = countryGroup.Key.ToString(); countryGroup.DisplayName = await CountryService.RetrieveCountryDisplayNameAsync(new RetrieveCountryParam { CultureInfo = viewModelParam.CultureInfo, IsoCode = countryCode }) ?? countryCode; foreach (var regionGroup in countryGroup.SubGroups) { regionGroup.DisplayName = await CountryService.RetrieveRegionDisplayNameAsync(new RetrieveRegionDisplayNameParam { CultureInfo = viewModelParam.CultureInfo, IsoCode = countryCode, RegionCode = regionGroup.Key.ToString() }); } } return(groups); }
protected virtual async Task <List <CustomProfile> > GetExtraStoresInfoAsync(List <Guid> storesIds, GetStoresParam getStoresParam) { var cacheKey = new CacheKey(CacheConfigurationCategoryNames.Store) { Scope = getStoresParam.Scope }; cacheKey.AppendKeyParts(GETEXSTRASTORESINFO_CACHE_KEYPART); var request = new GetProfileInstancesRequest { Ids = storesIds, EntityTypeName = "Store", ScopeId = getStoresParam.Scope }; return(await CacheProvider.GetOrAddAsync(cacheKey, () => OvertureClient.SendAsync(request)).ConfigureAwait(false)); }
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 <FindStoresQueryResult> GetStoresAsync(GetStoresParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } var cacheKey = new CacheKey(CacheConfigurationCategoryNames.Store) { Scope = param.Scope }; cacheKey.AppendKeyParts(GETSTORES_CACHE_KEYPART); var request = new FindStoresRequest { ScopeId = param.Scope, IncludeChildScopes = true, CultureName = param.CultureInfo.Name, Query = new Query { StartingIndex = 0, MaximumItems = int.MaxValue, IncludeTotalCount = false, Filter = new FilterGroup { Filters = GetStoreFilters() } } }; var stores = await CacheProvider.GetOrAddAsync(cacheKey, () => OvertureClient.SendAsync(request)).ConfigureAwait(false); // TODO: Remove this as soon as the FindStoresRequest returns localized display names. if (stores.Results.Any(s => s.DisplayName != null)) { return(stores); } // Try get DisplayNames if (param.IncludeExtraInfo) { var ids = stores.Results.Select(x => x.Id).ToList(); var extraStoresInfo = await GetExtraStoresInfoAsync(ids, param).ConfigureAwait(false); extraStoresInfo?.ForEach(extraStoreInfo => { extraStoreInfo.PropertyBag.TryGetValue("DisplayName", out object displayName); if (displayName == null) { return; } var store = stores.Results.FirstOrDefault(st => st.Id == extraStoreInfo.Id); if (store == null) { return; } store.DisplayName = displayName as Overture.ServiceModel.LocalizedString; }); } return(stores); }