Example #1
0
        // 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"));
            }
        }