public ResultDetailsViewModel()
        {
            #if DEBUG
            if (this.IsInDesignMode)
            {
                ObservableCollection<InventoryInfo> invInfo = new ObservableCollection<InventoryInfo>();
                invInfo.Add(new InventoryInfo() { NumberInStock = 33, Product = new ProductListItem() { Id = 33, Name = "Domaine De La Seigneurie Des Tourelles Saumur 2008 750 mL bottle" } });
                invInfo.Add(new InventoryInfo() { NumberInStock = 5600, Product = new ProductListItem() { Id = 56, Name = "Canadian" } });
                for (int i = 0; i < 20; i++)
                {
                    invInfo.Add(new InventoryInfo() { NumberInStock = 5600 + i, Product = new ProductListItem() { Id = i, Name = "Product " + i } });
                }

                StoreWithInventory sWithInv = new StoreWithInventory();
                sWithInv = new StoreWithInventory()
                {
                    Inventory = invInfo,
                    Store = new InvStore()
                    {
                        City = "City 123",
                        Address = "Address 123",
                        Latitude = 43.474249M,
                        Longitude = -79.732728M
                    }
                };

                this.StoreWithInventory = new StoreWithInventoryViewModel(sWithInv);
            }
            #endif
        }
 public StoreWithInventoryViewModel(StoreWithInventory storeWithInventory)
 {
     this.storeWithInventory = storeWithInventory;
     if (this.storeWithInventory.Inventory == null)
     {
         throw new ArgumentNullException("storeWithInventory.Inventory", "The storeWithInventory's Inventory object is null");
     }
     else
     {
         this.InventoryInfo = new ObservableCollection<InventoryInfoViewModel>();
         foreach (InventoryInfo inventoryInfo in this.storeWithInventory.Inventory)
         {
             this.InventoryInfo.Add(new InventoryInfoViewModel(inventoryInfo));
         }
     }
 }
        public List<StoreWithInventory> GetInventoriesWithRequest(InventoryRequest request)
        {
            List<StoreWithInventory> result = new List<StoreWithInventory>();
            // The result dictionary - key is the store ID, value is the store
            Dictionary<int, StoreWithInventory> resultStores = new Dictionary<int, StoreWithInventory>();

            using (traceManager.StartTrace("General"))
            {
                var userEntity = this.GetUserEntity();
                var productsToFind = request.GetProductIdsToFind(userEntity);

                // Get the results from the LCBO website
                List<LcboInventoryData2> lcboInventory = this.lcboService.RetrieveMatches(productsToFind);

                // Detect new and changed stores
                this.DetectNewAndChangedStores(lcboService, lcboInventory);

                // Get the store Ids
                var storeids = request.GetStoreNumbersToFind(this.domainContext, userEntity);

                //TODO: filter by store/product selection

                Dictionary<int, ProductListItem> productDictionary = new Dictionary<int, ProductListItem>();

                // The LCBO results filtered by the stores in the request
                var lcboInventoriesFiltered = from l in lcboInventory where storeids.Contains(l.StoreNumber) select l;

                foreach (var lcboInventoryItem in lcboInventoriesFiltered)
                {
                    StoreWithInventory currentStoreWithInventory;
                    if (resultStores.ContainsKey(lcboInventoryItem.StoreNumber))
                    {
                        // The current store is in the result dictionary, so set currentStore to it.
                        currentStoreWithInventory = resultStores[lcboInventoryItem.StoreNumber];
                    }
                    else
                    {
                        // The current store is not in the result dictionary.
                        // Set currentStore to be a new store
                        var Store = this.domainContext.Stores.Single(s => s.Id == lcboInventoryItem.StoreNumber);
                        var store = new InvStore()
                        {
                            Address = Store.Address,
                            City = Store.City,
                            Hours = Store.Hours,
                            Latitude = Store.Latitude,
                            Longitude = Store.Longitude,
                            StoreNumber = Store.Id
                        };

                        currentStoreWithInventory = new StoreWithInventory() { Store = store };
                        resultStores.Add(lcboInventoryItem.StoreNumber, currentStoreWithInventory);
                    }

                    // Inventory.CreateInventory(lcboInventoryItem.StoreNumber, lcboInventoryItem.ProductId);
                    // Set its level to that of the lcbo result value
                    ProductListItem productsVm = null;
                    if (productDictionary.ContainsKey(lcboInventoryItem.ProductId))
                    {
                        // Current product ID is in the dictionary, so set currentProduct to it
                        productsVm = productDictionary[lcboInventoryItem.ProductId];
                    }
                    else
                    {
                        // Current product ID is not in the dictionary
                        var product = this.domainContext.Products.Where(p => p.Id == lcboInventoryItem.ProductId).Include("Substance").Include("Container").First();
                        productsVm = new ProductListItem() { Name = product.Name };
                        productDictionary.Add(lcboInventoryItem.ProductId, productsVm);
                    }

                    // Create an inventory item
                    InventoryInfo currentInventory = new InventoryInfo
                    {
                        NumberInStock = lcboInventoryItem.NumberInStock,
                        Product = productsVm
                    };

                    // Set the current inventory's product to a new product based on the current product
                    // Attach the inventory item to the current store.  So we have Store.Inventory.Product and Store.Inventory.InventoryLevel.
                    currentStoreWithInventory.Inventory.Add(currentInventory);
                }

            }

            result = new List<StoreWithInventory>(resultStores.Values);

            return result;
        }