Пример #1
0
        public string FinalizeOrder(RepositoryHandler DH)
        {
            //check everything is valid
            //return with reason if not valid
            string result;

            if (!IsOrderSmallEnough())
            {
                return($"Too many pizzas in this order.  Orders may only have {MaxPizzas} pizzas maximum.");
            }
            if (!IsOrderCheapEnough())
            {
                return($"Too expenseive.  Maximum order price total is ${MaxOrderPrice}.");
            }
            if (!IsOrderNotEmpty())
            {
                return("Order must have at least one pizza.");
            }
            if (!IsOrderTwoHoursLaterV2(DH))
            {
                return("Order is being placed too soon after a recent order.  You may place one order with each location every two hours.");
            }
            if ((result = DoesLocationHaveAllIngredients(DH)) != null)  // ****THIS CHECK MUST BE LAST, WILL REMOVE INVENTORY USED
            {
                return($"Chosen location does not have the necessairy ingredients for all your pizzas.  It is short on {result}");
            }

            //if valid generate timestamp& order ID
            CurOrder.Timestamp = DateTime.Now;
            CurOrder.Id        = Math.Abs((int)CurOrder.Timestamp.Ticks);
            DH.OrderRepo.AddOrder(CurOrder);
            DH.LocRepo.Save();

            return(null);
        }
Пример #2
0
        public string DoesLocationHaveAllIngredients(RepositoryHandler DH)
        {
            //1: generate -List- of all ingredient types w/ appropiate quantity based on scalar
            List <Ingredient> allIngredients = BuildIngredientList(DH);

            return(DH.LocRepo.RemoveBulkStockv2(allIngredients, CurOrder.Store));
        }
Пример #3
0
        public bool IsOrderTwoHoursLater(RepositoryHandler DH)
        {
            //Both Users and Locations have an order history contianing order ids
            //Find intersection of User & location order histories from newest to oldest
            //if newest shared order <2 hrs reject, otherwise accept
            List <int> userOrders     = DH.UserRepo.GetUserByUsername(CurOrder.UserID).OrderHistory;
            List <int> locationOrders = DH.LocRepo.GetLocations().First(l => l.Name.Equals(CurOrder.Store)).OrderHistory;
            DateTime   orderTime;

            //new orders are always added to the end of the OrderHistory list, so go through newest orders first
            for (int i = userOrders.Count - 1; i >= 0; i--)
            {
                //get the order time off the user order we want to check
                orderTime = DH.OrderRepo.GetOrderByID(userOrders[i]).Timestamp;
                //if the most recent order being checked is already older than two hours
                //this is just for efficiency to not have to go through a user's entire order history since the beginning of time
                if (DateTime.Compare(DateTime.Now, orderTime.AddHours(2)) > 0)
                {
                    return(true);
                }

                //if an orderID is shared between user and location
                if (locationOrders.Contains(userOrders[i]))
                {
                    orderTime = DH.OrderRepo.GetOrderByID(userOrders[i]).Timestamp;
                    //if order was placed within the last two hours
                    if (DateTime.Compare(DateTime.Now, orderTime.AddHours(2)) < 0)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #4
0
 public bool ChangeLocation(string store, RepositoryHandler RH)
 {
     if (store != null && RH.LocRepo.LocationsContainsName(store))
     {
         CurOrder.Store = store;
         return(true);
     }
     return(false);
 }
Пример #5
0
 public bool StartNewPizza(string size, RepositoryHandler DH)
 {
     if (!DH.SPRepo.ContainsSize(size))
     {
         return(false);
     }
     ActivePizza       = new Pizza(size);
     ActivePizza.Price = DH.SPRepo.GetBasePrice(size) + DH.SPRepo.GetToppingPrice(size);
     return(true);
 }
Пример #6
0
 public bool ChangeCrustOnActivePizza(string crust, RepositoryHandler DH)
 {
     // if topping is not in valid list of toppings
     if (!(DH.IngRepo.GetIngredients().Any(t => t.Name.Equals(crust) && t.Type.Equals("crust"))))
     {
         return(false);
     }
     ActivePizza.CrustType = crust;
     return(true);
 }
Пример #7
0
 public bool ChangeSauceOnActivePizza(string sauce, RepositoryHandler DH)
 {
     //if sauce is not from valid list of toppings
     if (!(DH.IngRepo.GetIngredients().Any(t => t.Name.Equals(sauce) && t.Type.Equals("sauce"))))
     {
         return(false);
     }
     ActivePizza.SauceType = sauce;
     return(true);
 }
Пример #8
0
 public bool RemoveToppingFromActivePizza(string topping, RepositoryHandler DH)
 {
     if (ActivePizza.Toppings.Contains(topping))
     {
         ActivePizza.Toppings.Remove(topping);
         ActivePizza.Price -= DH.SPRepo.GetToppingPrice(ActivePizza.Size);
         return(true);
     }
     return(false);
 }
Пример #9
0
 public bool ChangeSizeOfActivePizza(string size, RepositoryHandler DH)
 {
     // if size is not in valid list of sizes
     if (!DH.SPRepo.ContainsSize(size))
     {
         return(false);
     }
     ActivePizza.Size  = size;
     ActivePizza.Price = DH.SPRepo.GetBasePrice(size) + DH.SPRepo.GetToppingPrice(size) * ActivePizza.Toppings.Count;
     return(true);
 }
Пример #10
0
        public bool IsOrderTwoHoursLaterV2(RepositoryHandler DH)
        {
            List <Order> UnionOrders = DH.OrderRepo.GetOrders().Where(o => o.UserID.Equals(CurOrder.UserID) && o.Store.Equals(CurOrder.Store)).ToList();

            foreach (var i in UnionOrders)
            {
                if (DateTime.Compare(DateTime.Now, i.Timestamp.AddHours(2)) < 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #11
0
 public bool AddToppingToActivePizza(string topping, RepositoryHandler DH)
 {
     // if topping is not in valid list of toppings
     if (!(DH.IngRepo.GetIngredients().Any(t => t.Name.Equals(topping) && t.Type.Equals("topping"))))
     {
         return(false);
     }
     //if topping already on pizza
     if (ActivePizza.Toppings.Contains(topping))
     {
         return(false);
     }
     ActivePizza.Toppings.Add(topping);
     ActivePizza.Price += DH.SPRepo.GetToppingPrice(ActivePizza.Size);
     return(true);
 }
Пример #12
0
        public List <Ingredient> BuildIngredientList(RepositoryHandler DH)
        {
            List <Ingredient> allIngredients = new List <Ingredient>();
            int amount;

            foreach (var p in CurOrder.Pizzas)
            {
                amount = DH.SPRepo.GetIngredientUsageScalar(p.Size);
                AddToIngredientList(allIngredients, new Ingredient(p.CrustType, amount, "crust"));
                AddToIngredientList(allIngredients, new Ingredient(p.SauceType, amount, "sauce"));
                foreach (var s in p.Toppings)
                {
                    AddToIngredientList(allIngredients, new Ingredient(s, amount, "topping"));
                }
            }

            return(allIngredients);
        }