public static StoreViewModel MapLocationToStore(Store.Location l)
        {
            StoreViewModel storeViewModel = new StoreViewModel();

            storeViewModel.Name            = l.LocationName;
            storeViewModel.NumItemsInStock = l.GetAllStock().ToList()
                                             .Where(item =>
                                                    item.Count > 0)
                                             .Count();

            storeViewModel.Orders = new List <OrderViewModel>();
            foreach (var order in l.LocationOrderHistory)
            {
                storeViewModel.Orders.Add(MapOrderToViewModel(order));
            }

            storeViewModel.NumOrders = storeViewModel.Orders.Count();

            return(storeViewModel);
        }
Exemple #2
0
        public ActionResult Stock([FromServices] IDbRepository repo, string store)
        {
            if (!string.IsNullOrWhiteSpace(store))
            {
                Store.Location            modelLocation = repo.GetLocation(store);
                List <StockItemViewModel> stocks        = new List <StockItemViewModel>();

                foreach (var item in modelLocation.GetAllStock())
                {
                    stocks.Add(StoreToViewMapper.MapStockToStockItem(item));
                }

                return(View(stocks));
            }
            else
            {
                _logger.LogError("Error: bad store name given.");
                ModelState.TryAddModelError("BadStore", "Error: bad store name given.");
                return(View(nameof(Stores), LoadandRetrieveStoreData(repo)));
            }
        }