Esempio n. 1
0
        /// <summary>
        /// Gets a store from memory and returns the Inventory as a List of Items.
        /// </summary>
        /// <param name="address"> Address of store you're looking for</param>
        /// <param name="location"> Name of store you're looking for</param>
        /// <returns>List of items responding to the store's inventory.</returns>
        public List <Model.Item> GetStoreInventory(string address, string location)
        {
            StoreLocation sL = new StoreLocation(address, location);

            try{
                Entity.DogStore dS = (
                    from DogStore in _context.DogStores where
                    DogStore.StoreAddress == address && DogStore.StoreName == location
                    select DogStore
                    ).Single();
                List <Entity.Inventory> iList = (
                    from Inventory in _context.Inventories where
                    Inventory.StoreId == dS.Id
                    select Inventory
                    ).ToList();
                List <Model.Item> itemList = new List <Model.Item>();
                foreach (Entity.Inventory i in iList)
                {
                    Entity.Dog dog = (
                        from Dog in _context.Dogs where
                        Dog.ItemId == i.DogId
                        select Dog
                        ).Single();
                    Log.Information("Here's the item I'm about to create");
                    Log.Information(dog.Breed);
                    Log.Information(dog.Gender.ToCharArray()[0].ToString());
                    Log.Information(dog.Price.ToString());
                    itemList.Add(new Model.Inventory(new Model.Dog(dog.Breed, dog.Gender.ToCharArray()[0], dog.Price), i.Quantity.Value));
                }
                return(itemList);
            } catch (Exception e) {
                Log.Error(e.Message + " some issue with finding this inventory");
                return(new List <Model.Item>());
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Method which searches for a quantity of a dog at a given store,
 /// throws an exception and returns null if item request is invalid.
 /// </summary>
 /// <param name="store">store to search for dogs</param>
 /// <param name="dog">dog customer wishes to purchase</param>
 /// <param name="quant">number of dogs customer wishes to purchase</param>
 /// <returns>Item if store has it</returns>
 public Model.Item FindItem(StoreLocation store, Dog dog, int quant)
 {
     try{
         string     add       = FindStore(store.Address, store.Location).Address;
         string     loc       = FindStore(store.Address, store.Location).Location;
         Entity.Dog searchDog = (
             from Dog in _context.Dogs where
             Dog.Breed == dog.Breed && Dog.Gender == dog.Gender.ToString()
             select Dog
             ).Single();
         Entity.DogStore dS = (
             from DogStore in _context.DogStores where
             DogStore.StoreAddress == store.Address && DogStore.StoreName == store.Location
             select DogStore
             ).Single();
         Entity.Inventory inv = (
             from Inventory in _context.Inventories where
             Inventory.StoreId == dS.Id && Inventory.DogId == searchDog.ItemId
             select Inventory
             ).Single();
         if (inv.Quantity < quant)
         {
             Console.WriteLine("Store doesn't have that many of that dog!");
             throw new Exception();
         }
         else
         {
             return(new Model.OrderItem(new Dog(searchDog.Breed, searchDog.Gender.ToCharArray()[0], searchDog.Price, searchDog.ItemId), quant));
         }
     }
     catch (Exception) {
         Log.Error("Item not found");
         return(null);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Method to add store location to the file. Adds a store to a file and returns
        /// the added store.
        /// </summary>
        /// <param name="store">StoreLocation to add to memory</param>
        // <returns>Return added StoreLocation</returns>
        public Model.StoreLocation AddStoreLocation(Model.StoreLocation store, Model.DogManager dogManager)
        {
            try{
                Entity.DogStore dogStore = new Entity.DogStore();
                dogStore.StoreName    = store.Location;
                dogStore.StoreAddress = store.Address;
                _context.DogStores.Add(
                    dogStore
                    );
                Entity.ManagesStore managesStore = new Entity.ManagesStore();

                _context.SaveChanges();
                Entity.DogStore dS = (
                    from DogStore in _context.DogStores where
                    DogStore.StoreAddress == dogStore.StoreAddress && DogStore.StoreName == dogStore.StoreName
                    select DogStore
                    ).Single();
                managesStore.ManagerId = dogManager.PhoneNumber;
                managesStore.StoreId   = dS.Id;
                _context.ManagesStores.Add(managesStore);
                _context.SaveChanges();
            }
            catch (Exception ex) {
                Log.Error(ex.Message + "error encountered in AddStoreLocation, this shouldn't happen");
            }
            return(store);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds an item to a stores inventory, creates dog if not found then adds it to the inventory
        /// </summary>
        /// <param name="store">Store to add inventory to</param>
        /// <param name="dog">Dog to add</param>
        /// <param name="quant">Quantity of Dog to add</param>
        /// <returns>Added item</returns>
        public Model.Item AddItem(StoreLocation store, Dog dog, int quant)
        {
            Item newItem = new Model.Inventory(dog, quant);

            try{
                Entity.Dog searchDog = (
                    from Dog in _context.Dogs where
                    Dog.Breed == dog.Breed && Dog.Gender == dog.Gender.ToString()
                    select Dog
                    ).Single();
                Entity.DogStore dS = (
                    from DogStore in _context.DogStores where
                    DogStore.StoreAddress == store.Address && DogStore.StoreName == store.Location
                    select DogStore
                    ).Single();

                try{
                    Entity.Inventory inv = (
                        from Inventory in _context.Inventories where
                        Inventory.StoreId == dS.Id && Inventory.DogId == searchDog.ItemId
                        select Inventory
                        ).Single();
                    inv.Quantity += quant;
                    _context.SaveChanges();
                    Log.Information("Item found, quanty incremented: " + quant.ToString());
                    return(newItem);
                }
                catch (Exception e) {
                    Log.Information(e.Message + "dog found but not inventory, adding dog to store's inventory");
                    Entity.Inventory inventory = new Entity.Inventory();
                    inventory.DogId    = searchDog.ItemId;
                    inventory.Quantity = quant;
                    inventory.StoreId  = dS.Id;
                    _context.Inventories.Add(inventory);
                    _context.SaveChanges();
                    return(newItem);
                }
            }
            catch (Exception e) {
                Log.Information(e.Message + "Dog not found, creating new dog");
                Entity.Dog newDog = new Entity.Dog();
                newDog.ItemId = new Random().Next();
                newDog.Breed  = dog.Breed;
                newDog.Gender = dog.Gender.ToString();
                newDog.Price  = dog.Price;
                _context.Dogs.Add(newDog);
                _context.SaveChanges();
                Entity.Dog      searchDog = newDog;
                Entity.DogStore dS        = (
                    from DogStore in _context.DogStores where
                    DogStore.StoreAddress == store.Address && DogStore.StoreName == store.Location
                    select DogStore
                    ).Single();
                Entity.Inventory inventory = new Entity.Inventory();
                inventory.DogId    = searchDog.ItemId;
                inventory.Quantity = quant;
                inventory.StoreId  = dS.Id;
                _context.Inventories.Add(inventory);
                _context.SaveChanges();
                return(newItem);
            }
        }