Exemplo n.º 1
0
        public ActionResult AddOrder(int Id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Library.Customer customer = CustomerRepo.GetCustomerById(Id);
                    OrderRepo.AddOrder(new Lib.Order
                    {
                        CustomerId = customer.Id,
                        StoreId    = customer.StoreId,
                        TimePlaced = DateTime.Now
                    });

                    var order = OrderRepo.GetAllOrders().Last();
                    var inv   = StoreRepo.GetInventoryProducts(StoreRepo.GetInventory(customer.StoreId));
                    foreach (Lib.Product item in inv)
                    {
                        OrderRepo.AddProduct(order.Id, item);
                    }

                    return(RedirectToAction("Index", "Cart",
                                            new { @id = order.Id }));
                }
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 2
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"));
            }
        }