Exemplo n.º 1
0
        public ActionResult AddToOrder(int id, AddInventoryViewModel model)
        {
            try
            {
                var order = OrderRepo.GetOrderById(id);
                IEnumerable <Lib.Inventory> libInv      = StoreRepo.GetInventory(order.StoreId);
                IEnumerable <Lib.Product>   libProducts = StoreRepo.GetInventoryProducts(libInv);


                AddInventoryViewModel avm = new AddInventoryViewModel
                {
                    OrderId   = id,
                    StoreId   = order.StoreId,
                    ProductId = model.ProductId,
                    Val       = model.Val
                };

                OrderRepo.AddToOrder(id, order.StoreId, avm.ProductId, avm.Val);

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