public IActionResult OrderHistory(OrderViewModel model) {
      List<OrderModel> orders;
      try {
        _ = userLoggedIn; // exception not caught if you just use uLI
        orders = _repo.GetOrdersForUser(userLoggedIn);
      } catch (NullReferenceException) {
        model.ReasonForError = "You are not logged in. Please return to the main page to login and try again.";
        return View("Error", model);
      }

      List<OrderViewClass> orderHistory = new List<OrderViewClass>();
      foreach (OrderModel order in orders) {
        StringBuilder toppings = new StringBuilder();
        foreach (string topping in order.Toppings.Split(',')) {
          int toppingID;
          if (!int.TryParse(topping, out toppingID)) {
            Console.WriteLine($"Database error: Expected integer for pizza ID, received {topping}");
            toppings.Append("Error, ");
            continue;
          }
          ToppingModel top = _repo.GetTopping(toppingID);
          toppings.Append($"{top.Name}, ");
        }
        toppings.Remove(toppings.Length - 2, 2);
        OrderViewClass orderView = new OrderViewClass{
          OrderID = order.OrderID,
          Created = order.Created,
          Size = order.Size,
          Crust = _repo.GetCrust(order.CrustID).Name,
          Toppings = toppings.ToString(),
          Quantity = order.Quantity,
          Cost = order.TotalCost,
          StoreName = _repo.GetStore(order.StoreID).Name
        };
        if (order.PizzaID == 0) {
          orderView.Pizza = "Custom";
        } else {
          try {
            orderView.Pizza = _repo.GetPizza(order.PizzaID).Name;
          } catch (NullReferenceException) {
            Console.WriteLine($"Database error: Could not find a pizza with ID {order.PizzaID} in the Pizza table");
            orderView.Pizza = "Error";
          }
        }
        orderHistory.Add(orderView);
      }
      model.OrderHistory = orderHistory;
      return View(model);
    }
        public IActionResult SalesReport(SalesReportViewModel model)
        {
            _ = storeLoggedIn;
            model.StoreName = _repo.GetStore(storeLoggedIn).Name;

            bool submitClicked = Request.Form["submit"].ToString() != "";
            bool backClicked   = Request.Form["back"].ToString() != "";

            if (submitClicked && backClicked)
            {
                Console.WriteLine("Both buttons in Sales Report registered as clicked");
                model.ReasonForError = "There was an error processing your request. Please try again.";
                return(View("SalesReport", model));
            }
            else if (submitClicked)
            {
                List <OrderModel> listOfOrders = _repo.GetOrders();

                Dictionary <DateTime, OrderViewModel> salesReport = new Dictionary <DateTime, OrderViewModel>();
                foreach (OrderModel order in listOfOrders)
                {
                    DateTime dayOfOrder            = order.Created.Date;
                    DateTime startingDayOfInterval = dayOfOrder;
                    if (model.Interval == 7)
                    {
                        startingDayOfInterval = dayOfOrder.AddDays(-((int)dayOfOrder.DayOfWeek));
                    }
                    else if (model.Interval == 30)
                    {
                        startingDayOfInterval = dayOfOrder.AddDays(-(dayOfOrder.Day - 1));
                    }
                    else
                    {
                        model.ReasonForError = "Please select an interval";
                        return(View("SalesReport", model));
                    }

                    StringBuilder toppings = new StringBuilder();
                    foreach (string topping in order.Toppings.Split(','))
                    {
                        int toppingID;
                        if (!int.TryParse(topping, out toppingID))
                        {
                            Console.WriteLine($"Database error: Expected integer for pizza ID, received {topping}");
                            toppings.Append("Error, ");
                            continue;
                        }
                        ToppingModel top = _repo.GetTopping(toppingID);
                        toppings.Append($"{top.Name}, ");
                    }
                    toppings.Remove(toppings.Length - 2, 2);
                    OrderViewClass orderView = new OrderViewClass {
                        UserID    = order.UserID,
                        OrderID   = order.OrderID,
                        Created   = order.Created,
                        Size      = order.Size,
                        Crust     = _repo.GetCrust(order.CrustID).Name,
                        Toppings  = toppings.ToString(),
                        Quantity  = order.Quantity,
                        Cost      = order.TotalCost,
                        StoreName = _repo.GetStore(order.StoreID).Name
                    };
                    if (order.PizzaID == 0)
                    {
                        orderView.Pizza = "Custom";
                    }
                    else
                    {
                        try {
                            orderView.Pizza = _repo.GetPizza(order.PizzaID).Name;
                        } catch (NullReferenceException) {
                            Console.WriteLine($"Database error: Could not find a pizza with ID {order.PizzaID} in the Pizza table");
                            orderView.Pizza = "Error";
                        }
                    }

                    try {
                        salesReport[startingDayOfInterval].OrderHistory.Add(orderView);
                    } catch (KeyNotFoundException) {
                        salesReport.Add(startingDayOfInterval, new OrderViewModel {
                            OrderHistory = new List <OrderViewClass> {
                                orderView
                            }
                        });
                    }
                }

                model.SalesReport = new Dictionary <DateTime, OrderViewModel>();
                foreach (DateTime startDate in salesReport.Keys)
                {
                    OrderViewModel orderView = salesReport[startDate];
                    model.SalesReport.Add(startDate, new OrderViewModel {
                        OrderHistory = new List <OrderViewClass>()
                    });
                    foreach (OrderViewClass order in orderView.OrderHistory)
                    {
                        string pizza = order.Pizza;
                        List <OrderViewClass> srOrderHistory = model.SalesReport[startDate].OrderHistory;
                        int i;
                        for (i = 0; i < srOrderHistory.Count(); i++)
                        {
                            OrderViewClass srOrder = model.SalesReport[startDate].OrderHistory[i];
                            if (srOrder.Pizza == pizza)
                            {
                                break;
                            }
                        }

                        if (i == srOrderHistory.Count())
                        {
                            srOrderHistory.Add(new OrderViewClass {
                                Pizza    = pizza,
                                Quantity = 1,
                                Cost     = order.Cost
                            });
                        }
                        else
                        {
                            srOrderHistory[i].Quantity += 1;
                            srOrderHistory[i].Cost     += order.Cost;
                        }
                        model.SalesReport[startDate].IntervalQuantity += 1;
                        model.SalesReport[startDate].IntervalSales    += order.Cost;
                    }
                }

                return(View("SalesReport", model));
            }
            else // if backClicked
            {
                StoreViewModel storeModel = new StoreViewModel {
                    StoreName = model.StoreName,
                    ID        = storeLoggedIn
                };
                return(View("Store", storeModel));
            }
        }
        public IActionResult OrderHistory(StoreViewModel model)
        {
            model.ID           = storeLoggedIn;
            model.StoreName    = _repo.GetStore(model.ID).Name;
            model.OrderHistory = new List <OrderViewClass>();

            bool submitClicked = Request.Form["submit"].ToString() != "";
            bool backClicked   = Request.Form["back"].ToString() != "";

            if (submitClicked && backClicked)
            {
                model.ReasonForError = "There was a problem processing your request. Please try again.";
                return(View("OrderHistory", model));
            }
            else if (backClicked)
            {
                return(Redirect("/Store/Store"));
            }

            if (model.OptionSelected != 1 && model.OptionSelected != 2)
            {
                model.ReasonForError = "There was an error processing your request. Please try again.";
                return(View("OrderHistory", model));
            }

            List <OrderModel> orders;

            if (model.OptionSelected == 1)
            {
                orders = _repo.GetOrdersForStore(model.ID);
            }
            else // if model.OptionSelected == 2
            {
                int parsedUserID;
                if (!int.TryParse(model.FilterHistoryToUser, out parsedUserID))
                {
                    model.ReasonForError = "Please enter a positive integer for a user ID";
                    return(View("OrderHistory", model));
                }
                orders = _repo.GetOrdersForStoreAndUser(model.ID, parsedUserID);
            }

            foreach (OrderModel order in orders)
            {
                StringBuilder toppings = new StringBuilder();
                foreach (string topping in order.Toppings.Split(','))
                {
                    int toppingID;
                    if (!int.TryParse(topping, out toppingID))
                    {
                        Console.WriteLine($"Database error: Expected integer for pizza ID, received {topping}");
                        toppings.Append("Error, ");
                        continue;
                    }
                    ToppingModel top = _repo.GetTopping(toppingID);
                    toppings.Append($"{top.Name}, ");
                }
                toppings.Remove(toppings.Length - 2, 2);
                OrderViewClass orderView = new OrderViewClass {
                    UserID    = order.UserID,
                    OrderID   = order.OrderID,
                    Created   = order.Created,
                    Size      = order.Size,
                    Crust     = _repo.GetCrust(order.CrustID).Name,
                    Toppings  = toppings.ToString(),
                    Quantity  = order.Quantity,
                    Cost      = order.TotalCost,
                    StoreName = _repo.GetStore(order.StoreID).Name
                };
                if (order.PizzaID == 0)
                {
                    orderView.Pizza = "Custom";
                }
                else
                {
                    try {
                        orderView.Pizza = _repo.GetPizza(order.PizzaID).Name;
                    } catch (NullReferenceException) {
                        Console.WriteLine($"Database error: Could not find a pizza with ID {order.PizzaID} in the Pizza table");
                        orderView.Pizza = "Error";
                    }
                }
                model.OrderHistory.Add(orderView);
            }

            model.ReasonForError = $"{model.OrderHistory.Count()} records found";
            return(View("OrderHistory", model));
        }