/// <summary> /// Displays the information of an Order, (Customer who made the order, Location order was placed, and products ordered) /// </summary> /// <param name="orderHistory"></param> private static void DisplayOrder(OrderHistory orderHistory, bool viewingLocation) { var customerRef = OrderHistoryRepo.getCustomerRef(orderHistory); Customer customer = customerRef.Customer; var locationRef = OrderHistoryRepo.getLocationRef(orderHistory); Location location = locationRef.Location; //List<Orders> orders = Program.context.Orders.Include(oh => oh.OrderHistory).ToList(); List <Orders> orders = OrdersRepo.GetAllOrdersInHistory().ToList(); // added .ToList() in foreach b/c somewhere under the hood, something was indirectly changing my list of orderhistories. // so by adding .ToList() it copies the values in orders to a separate new list at the start of the foreach foreach (var order in orders.ToList()) { if (order.OrderHistoryId != orderHistory.OrderHistoryId) { orders.Remove(order); } } Console.WriteLine(); if (!viewingLocation) { Console.WriteLine($"Customer: {customer.FirstName} {customer.LastName}"); } Console.WriteLine($"Store Location: {location.Address}, {location.City}, {location.State}"); Console.WriteLine("Purchased:"); double totalSum = 0.0; foreach (var order in orders) { Console.WriteLine($" {productRepo.GetById(order.ProductId).Name}"); Console.WriteLine($" Amount Bought: {order.AmountOrdered}"); totalSum += OrdersRepo.CalculateTotal(productRepo.GetById(order.ProductId), order); } Console.WriteLine($"Total cost: ${totalSum}"); }
public void Get_Correct_Customer(int customerID, int orderHistoryID) { OrderHistoryRepository orderHistoryRepo = new OrderHistoryRepository(context); OrderHistory orderHistory = orderHistoryRepo.GetById(orderHistoryID); OrderHistory orderHistory1 = orderHistoryRepo.getCustomerRef(orderHistory); Customer customer = orderHistory1.Customer; Assert.True(customer.CustomerId == customerID); }