Ejemplo n.º 1
0
 public void SingleProductNotInUsersList()
 {
     InventoryRequest request = new InventoryRequest();
     request.ProductId = 998; // A product that exists but is not in the user's list
     User user = this.DomainContext.Users.Single(u => u.Username == "jmclachl");
     var products = request.GetProductIdsToFind(user);
     Assert.AreEqual(1, products.Count());
     Assert.IsTrue(products.Contains(request.ProductId));
 }
Ejemplo n.º 2
0
 public void AllUsersProducts()
 {
     InventoryRequest request = new InventoryRequest();
     request.ProductId = 998; // A product that exists but is not in the user's list
     request.ProductIdType = ProductIdType.AllUsersProducts;
     User user = this.DomainContext.Users.Single(u => u.Username == "jmclachl");
     var products = request.GetProductIdsToFind(user);
     Assert.AreEqual(3, products.Count());
     Assert.IsFalse(products.Contains(request.ProductId));
 }
Ejemplo n.º 3
0
 public void SingleProductThatDoesntExist()
 {
     InventoryRequest request = new InventoryRequest();
     request.ProductId = 999; // A product that doesn't exist
     User user = this.DomainContext.Users.Single(u => u.Username == "jmclachl");
     var products = request.GetProductIdsToFind(user);
     Assert.AreEqual(1, products.Count());
     Assert.IsTrue(products.Contains(request.ProductId));
 }
Ejemplo n.º 4
0
 public void TestRequest()
 {
     InventoryRequest request = new InventoryRequest();
     request.ProductId = 99;
     request.ProductIdType = ProductIdType.AllUsersProducts;
     request.StoreNumber = 45;
     request.StoreNumberType = StoreNumberType.AllUsersStores;
     User user = this.DomainContext.Users.Single(u => u.Username == "jmclachl");
     var products = request.GetProductIdsToFind(user);
     Assert.AreEqual(3, products.Count());
     var stores = request.GetStoreNumbersToFind(this.DomainContext, user);
     Assert.AreEqual(3, stores.Count());
 }
Ejemplo n.º 5
0
        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;
        }