/* * public IEnumerable<ItemCount> GetStoreStocks(Store.Location l) * { * IEnumerable<ItemCount> ModdelStock = l.GetAllStock(); * //may have uncommitted changes in an asynchronus enviorment * //no way to reconsile stock changes, and there shouldn't be any discrepency ... * //so just returning * return ModdelStock; * } */ /// <summary> /// Get a specific store from the db. /// </summary> /// <param name="storeName"></param> /// <returns></returns> Store.Location IDbRepository.GetLocation(string storeName) { using MyStoreDbContext context = ConnectToDB(); Location store = context.Locations .Where(str => str.LocationName == storeName) .Include(str => str.Invintories) .FirstOrDefault(); if (store != null) { if (Locations.Instance.HasLocation(storeName)) { return(Locations.Instance.GetLocation(storeName)); } else { //create location Store.Location newLocation = Locations.Instance.RegisterLocation(storeName); //add invintory foreach (Invintory inv in store.Invintories) { newLocation.AddInventory(inv.ItemName, inv.Quantity); } return(newLocation); } } else { return(null); } }
/// <summary> /// Use the location to get the invintory added to the model. /// </summary> /// <remarks> /// ONLY for use when initializing a store /// </remarks> /// <param name="location">The location to fetch and add all stocks to</param> private void AddStockToModel(MyStoreDbContext context, Location location) { Store.Location modelLoc = Store.Locations.Instance.GetLocation(location.LocationName); foreach (Invintory invintory in context.Invintories .Where(inv => inv.StoreLocation == location.LocationName)) { modelLoc.AddInventory(invintory.ItemName, invintory.Quantity); } }