// GET: Cart public ActionResult Index(int Id) { ViewBag.orderId = Id; Library.Order order = OrderRepo.GetOrderById(Id); IEnumerable <Lib.Inventory> libInv = StoreRepo.GetInventory(order.StoreId); IEnumerable <Lib.Product> libProducts = StoreRepo.GetInventoryProducts(libInv); IEnumerable <InventoryViewModel> ivm = libProducts.Select(x => new InventoryViewModel { Id = x.Id, Name = x.Name, Price = (decimal)x.Price, Quantity = libInv.First(i => i.ProductId == x.Id && i.StoreId == order.StoreId).Quantity, StoreName = StoreRepo.GetStoreById(order.StoreId).Name, CustomerName = CustomerRepo.GetCustomerById(order.CustomerId).FirstName + ' ' + CustomerRepo.GetCustomerById(order.CustomerId).LastName }); IEnumerable <Lib.OrderItems> libOrderItems = OrderRepo.GetOrderItems(order.Id); IEnumerable <Lib.Product> libOrderProducts = OrderRepo.GetOrderProducts(libOrderItems); IEnumerable <CartViewModel> cvm = libOrderProducts.Select(x => new CartViewModel { Name = x.Name, Price = (decimal)x.Price, Quantity = libOrderItems.First(i => i.ProductId == x.Id && i.OrderId == order.Id).Quantity, Ivm = ivm, Total = OrderRepo.OrderTotal(order.Id) }); return(View(cvm)); }
// GET: Order public ActionResult Index(int Id) { if (CustomerRepo.ContainsId(Id)) { ViewBag.customerId = Id; Library.Customer customer = CustomerRepo.GetCustomerById(Id); IEnumerable <Lib.Inventory> libInv = StoreRepo.GetInventory(customer.StoreId); IEnumerable <Lib.Product> libProducts = StoreRepo.GetInventoryProducts(libInv); IEnumerable <InventoryViewModel> ivm = libProducts.Select(x => new InventoryViewModel { Id = x.Id, Name = x.Name, Price = (decimal)x.Price, Quantity = libInv.First(i => i.ProductId == x.Id && i.StoreId == customer.StoreId).Quantity, StoreName = StoreRepo.GetStoreById(customer.StoreId).Name, CustomerName = customer.FirstName + ' ' + customer.LastName }); return(View(ivm)); } else { return(RedirectToAction("Index", "Home")); } }