public IActionResult CustomerOrders(int?id) { if (!Util.IsLoggedIn(_cache)) { return(RedirectToAction("Login", "Customer")); } ViewData["CustomerOrders"] = "active"; ViewModel viewModel = new ViewModel(); var orderProducts = DbManipulation.GetCustomerOrderProducts(_db, id); var customers = DbManipulation.GetCustomers(_db).ToList(); if (id == 0 || id == null) { ViewData["CurrentCustomer"] = "none"; } else { ViewData["CurrentCustomer"] = customers.FirstOrDefault(c => c.CustomerId == id).UserName; } if (orderProducts.ToList().Count == 0) { OrderView orderViewNone = viewModel.CreateEmptyOrderView(customers); return(View("CustomerOrders", orderViewNone)); } List <Order> orders = DbManipulation.GetOrdersFromOrderProducts(_db, orderProducts); OrderView orderView = viewModel.CreateOrderView(orders, customers); return(View("CustomerOrders", orderView)); }