예제 #1
0
 /// <summary>
 /// Dereserve ingredients reserved by an order. Throws, if order bottles include a bottle which is not present
 /// in the recipe, or if the recipe includes multiple portions with same name.
 /// </summary>
 /// <param name="order"></param>
 /// <returns>True if successfull</returns>
 public bool Dereserve(Order order)
 {
     // Add the reserved amount back to the bottles reserved originaly by the order
     foreach (var b in order.BottlesToUse)
     {
         // Amount added is the amount of portions multiplied by the portion amount specified in the recipe
         b.Item1.Volume += b.Item2 * order.GetRecipe().Portions().Single(p => p.Name == b.Item1.Name).Amount;
     }
     return(true);
 }
예제 #2
0
        public List <Tuple <Bottle, int> > Reserve(Order order)
        {
            const string funcName = nameof(Reserve);

            // Should never happen, exception maybe?
            if (AmountAvailable(order.GetRecipe()) < order._howMany)
            {
                Log.ErrorEx(funcName, $"Not enough ingredients available for the drink being reserved in order {order.OrderId}");
                return(null);
            }
            var result = new List <Tuple <Bottle, int> >();

            // Iterate through all portions in order
            foreach (Portion p in order.GetRecipe().Portions())
            {
                // Get all bottles with that name and iteratre through them until required amount is reached
                var amountToPour = p.Amount * order._howMany;
                var bottles      = Find(p.Name);
                foreach (Bottle b in bottles)
                {
                    // Check how much liquid left in bottle TODO: How to handle removelimit
                    var available = (b.Volume - _removelimit / 2) / p.Amount;
                    if (available < order._howMany)
                    {
                        b.Volume     -= available * p.Amount;
                        amountToPour -= available * p.Amount;
                        result.Add(new Tuple <Bottle, int>(b, available));
                    }
                    else
                    {
                        // Last bottle to consider, add to result and return
                        b.Volume -= amountToPour;
                        result.Add(new Tuple <Bottle, int>(b, order._howMany));
                        return(result);
                    }
                }
                Log.FatalEx(funcName, $"No bottles or not enough bottles to reserve the order {order.OrderId}");
                throw new NotImplementedException();
            }
            Log.ErrorEx(funcName, $"No portions in the drink being reserved in order {order.OrderId}");
            return(null);
        }