protected virtual async Task <bool> IsInventoryEnabledAsync(GetStoreInventoryViewModelParam param)
        {
            var productSettingsViewModel =
                await ProductSettingsViewService.GetProductSettings(param.Scope, param.CultureInfo);

            return(productSettingsViewModel.IsInventoryEnabled);
        }
 protected async virtual Task <Dictionary <string, string> > GetInventoryStatusDisplayNamesAsync
     (GetStoreInventoryViewModelParam param, bool isEnabled)
 {
     return(isEnabled
         ? await LookupService.GetLookupDisplayNamesAsync(new GetLookupDisplayNamesParam
     {
         CultureInfo = param.CultureInfo,
         LookupType = LookupType.Order,
         LookupName = "LineItemStatus"
     })
         : null);
 }
Пример #3
0
        protected virtual async Task <List <Overture.ServiceModel.Customers.Stores.Store> > GetStores(
            GetStoreInventoryViewModelParam viewModelParam,
            InventoryItemStatusDetailsQueryResult overtureInventoryItems)
        {
            var getStoresTasks = overtureInventoryItems.Results.Select(inventoryItem =>
                                                                       StoreRepository.GetStoreByNumberAsync(new GetStoreByNumberParam
            {
                Scope            = viewModelParam.Scope,
                CultureInfo      = viewModelParam.CultureInfo,
                StoreNumber      = inventoryItem.FulfillmentLocationNumber,
                IncludeSchedules = true,
                IncludeAddresses = true
            }));

            var result = await Task.WhenAll(getStoresTasks).ConfigureAwait(false);

            return(result.Where(s => s != null && s.IsActive).ToList());
        }
 protected static void ValidateParam(GetStoreInventoryViewModelParam 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");
     }
     if (string.IsNullOrWhiteSpace(viewModelParam.Sku))
     {
         throw new ArgumentNullException("sku");
     }
 }
Пример #5
0
        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);
        }