/// <summary>
        /// Method that gets location's order history based on the branch name
        /// </summary>
        /// <param name="l"></param>
        /// <returns></returns>
        public List <BL.Orders> GetLocationHistory(BL.Location l)
        {
            using var context = GetContext();
            List <BL.Orders> output = new List <BL.Orders>();
            List <Orders>    dbOrd  = context.Orders.Where(o => o.Location.BranchName == l.BranchName).ToList();

            foreach (Orders o in dbOrd)
            {
                output.Add(ParseOrder(o));
            }
            return(output);
        }
        /// <summary>
        /// Method that returns inventory of a certain branch
        /// </summary>
        /// <param name="location"></param>
        /// <returns>List of Business Logic Inventories</returns>
        public List <BL.Inventory> GetInventory(BL.Location location)
        {
            using var context = GetContext();
            List <Inventory>    getInvent = context.Inventory.Where(i => i.Location.BranchName == location.BranchName).ToList();
            List <BL.Inventory> theInvent = new List <BL.Inventory>();

            foreach (Inventory i in getInvent)
            {
                theInvent.Add(ParseInventory(i));
            }
            return(theInvent);
        }
        /// <summary>
        /// Method that converts Business Logic Location objects to Data Access Location objects for DB interaction
        /// </summary>
        /// <param name="location"></param>
        /// <returns>Data Access Location</returns>
        internal Location ParseLocation(BL.Location location)
        {
            Location local = new Location()
            {
                BranchName = location.BranchName,
                Street     = location.StoreAddress.Street,
                City       = location.StoreAddress.City,
                State      = location.StoreAddress.State.ToString(),
                ZipCode    = location.StoreAddress.Zipcode.ToString()
            };

            return(local);
        }
        /// <summary>
        /// Method that returns available inventory of a certain branch
        /// </summary>
        /// <param name="location"></param>
        /// <returns>List of Business Logic Inventories</returns>
        public List <BL.Inventory> GetAvailInventory(BL.Location location)
        {
            //gets inventory from location in db
            using var context = GetContext();
            List <BL.Inventory> availInventory = new List <BL.Inventory>();
            List <Inventory>    getInvent      = context.Inventory.Where(i => i.Location.BranchName == location.BranchName).ToList();

            foreach (Inventory i in getInvent)
            {
                if (i.Stock > 0)
                {
                    availInventory.Add(ParseInventory(i));
                }
            }
            return(availInventory);
        }
 /// <summary>
 /// Method that converts Data Access Location object to a Business Logic Location object for interacting with UI
 /// </summary>
 /// <param name="location"></param>
 /// <returns>Business Logic Location</returns>
 internal BL.Location ParseLocation(Location location)
 {
     BL.Location local = new BL.Location()
     {
         BranchName   = location.BranchName,
         StoreAddress = new BL.Address()
         {
             Street  = location.Street,
             City    = location.City,
             State   = (BL.States)Enum.Parse(typeof(BL.States), location.State, true),
             Zipcode = int.Parse(location.ZipCode)
         },
         StoreInventory = GetParsedStoreInventory(location)
     };
     return(local);
 }
        /// <summary>
        /// Method that updates the inventory in DB
        /// </summary>
        /// <param name="inv"></param>
        /// <param name="local"></param>
        public void UpdateInventory(BL.Inventory inv, BL.Location local)
        {
            //updates store inventory and also rejects orders with too high quantity
            using var context = GetContext();
            if (inv.Stock < 1)
            {
                throw new BL.InvalidStockException("Quantity should be greater than 0");
            }
            Inventory item = context.Inventory.Single(i => i.LocationId == context.Location.Single(l => l.BranchName == local.BranchName).LocationId&& i.ProductId == context.Product.First(p => p.Name == inv.Prod.Name).ProductId);

            if (inv.Stock > item.Stock)
            {
                throw new InsufficientStockException("Stock Insufficient");
            }
            item.Stock = item.Stock - inv.Stock;
            context.SaveChanges();
            Log.Information("Inventory Updated");
        }