Exemplo n.º 1
0
        public ActionResult SaveOrder(OrderIndexVM orderIndexVM)
        {
            //saves to the table
            var order = new Order
            {
                CustomerID = orderIndexVM.CustomerID,
                LocationID = orderIndexVM.LocationID,
                Total      = GetTotal(orderIndexVM.DrinkOrders)
            };

            order = _orderBL.AddOrder(order);
            foreach (var item in orderIndexVM.DrinkOrders)
            {
                if (item.Quantity > 0)
                {
                    var drinkOrder = new DrinkOrder
                    {
                        DrinkId  = item.DrinkId,
                        OrderId  = order.OrderID,
                        Quantity = item.Quantity
                    };
                    _orderBL.AddDrinkOrder(drinkOrder);
                }
                var inventory = _inventoryBL.GetInventoryByLocationIDAndDrinkID(order.LocationID, item.DrinkId);
                if (inventory != null)
                {
                    inventory.Quantity -= item.Quantity;
                    _inventoryBL.UpdateInventory(inventory);
                }
            }



            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
0
        public ActionResult PlaceOrder(OrderIndexVM orderIndexVM)
        {
            string drinkOrderString = JsonConvert.SerializeObject(orderIndexVM.DrinkOrders);

            TempData["DrinkOrders"]    = drinkOrderString;
            orderIndexVM.ErrorMessages = new List <string>();
            foreach (var drinkOrder in orderIndexVM.DrinkOrders)
            {
                if (drinkOrder.Quantity > 0)
                {
                    var inventory = _inventoryBL.GetInventoryByLocationIDAndDrinkID(orderIndexVM.LocationID, drinkOrder.DrinkId);
                    if (inventory.Quantity < drinkOrder.Quantity)
                    {
                        orderIndexVM.ErrorMessages.Add($"Not enough {drinkOrder.DrinkName} \r\n ");
                        orderIndexVM.ErrorMessages.Add($"We currently have {inventory.Quantity} in stock at this location \r\n");
                    }
                }
            }
            if (orderIndexVM.ErrorMessages != null && orderIndexVM.ErrorMessages.Any())
            {
                return(RedirectToAction("Index", "Order", orderIndexVM));
            }


            return(RedirectToAction("ConfirmOrder", "Order", orderIndexVM));
        }
        public ActionResult Index()
        {
            //OrderIndexVM model = OrderService.GetOrderIndexVM();
            OrderIndexVM model = new OrderIndexVM();

            model.OrderStatuses = EnumHelpers.GetEnumBinderListJson <OrderStatusEnum>();
            return(View(model));
        }
Exemplo n.º 4
0
        // GET: Orders
        public async Task <IActionResult> Index(string company, string year)
        {
            var filterdOrders = new List <Order>();

            if (company != null)
            {
                int id = int.Parse(company);
                filterdOrders = await _context.Orders
                                .Include(c => c.Company)
                                .Where(i => i.Company.Id == id)
                                .ToListAsync();
            }
            else
            {
                filterdOrders = await _context.Orders
                                .Include(c => c.Company)
                                .ToListAsync();
            }

            if (year != null)
            {
                int parsedYear = int.Parse(year);
                filterdOrders = filterdOrders
                                .Where(y => y.Date.Year == parsedYear)
                                .ToList();
            }


            var model = new OrderIndexVM()
            {
                Companies = await _context.Companies
                            .Select(c =>

                                    new SelectListItem()
                {
                    Value = c.Id.ToString(),
                    Text  = c.Name
                }
                                    )
                            .ToListAsync(),

                Years = _context.Orders.Select(y =>

                                               new SelectListItem()
                {
                    Value = y.Date.Year.ToString(),
                    Text  = y.Date.Year.ToString()
                }).AsEnumerable().Distinct(new SelectListItemComparer()).ToList(),

                Orders = filterdOrders
            };

            return(View(model));
        }
Exemplo n.º 5
0
        public IActionResult Index(string korisnik = null)
        {
            OrderIndexVM model = new OrderIndexVM();

            if (String.IsNullOrEmpty(korisnik))
            {
                model.order = _context.Orders.Where(x => x.IsProcessed).Include(a => a.ApplicationUser).ToList();
            }
            else
            {
                model.order = _context.Orders.Where(x => x.IsProcessed).Include(a => a.ApplicationUser).
                              Where(a => a.ApplicationUser.FullName.Contains(korisnik)).ToList();
            }
            return(View(model));
        }
Exemplo n.º 6
0
        public IActionResult Index(OrderIndexVM orderIndexVM = null)
        {
            /*
             * viewbag is temp placeholder for passing info to the page we dont care about in the VM itself
             * we dedicate the responsibility for repo to give the row data of the table
             * we leave mapping to the controller
             */
            if (orderIndexVM == null || orderIndexVM.CustomerID == 0)
            {
                orderIndexVM = new OrderIndexVM();
                var drinks = _drinkBL.GetDrinks();
                orderIndexVM.DrinkOrders = drinks
                                           .Select(i => new DrinkOrderVM
                {
                    DrinkId   = i.DrinkId,
                    DrinkName = i.DrinkName,
                    ABV       = i.ABV,
                    Price     = i.Price
                }).ToList();
            }
            else
            {
                string drinkOrderString = TempData["DrinkOrders"].ToString();
                orderIndexVM.DrinkOrders = JsonConvert.DeserializeObject <List <DrinkOrderVM> >(drinkOrderString);
            }

            var customers = _customerBL.GetCustomers();

            ViewBag.Customers = customers
                                .Select(i => new SelectListItem
            {
                Value = i.CustomerId.ToString(),
                Text  = i.Name
            }).ToList();

            var locations = _locationBL.GetLocations();

            ViewBag.Locations = locations
                                .Select(i => new SelectListItem
            {
                Value = i.LocationID.ToString(),
                Text  = $"{i.LocationName}, {i.State}"
            }).ToList();


            return(View(orderIndexVM));
        }
Exemplo n.º 7
0
        public IActionResult ConfirmOrder(OrderIndexVM orderIndexVM)
        {
            string drinkOrderString = TempData["DrinkOrders"].ToString();

            orderIndexVM.DrinkOrders = JsonConvert.DeserializeObject <List <DrinkOrderVM> >(drinkOrderString);
            var customer = _customerBL.GetCustomerByID(orderIndexVM.CustomerID);

            if (customer != null)
            {
                orderIndexVM.CustomerName = customer.Name;
            }

            var location = _locationBL.GetSpecifiedLocation(orderIndexVM.LocationID);

            if (location != null)
            {
                orderIndexVM.LocationName = location.LocationName;
                orderIndexVM.State        = location.State;
            }
            orderIndexVM.Total = GetTotal(orderIndexVM.DrinkOrders);

            return(View(orderIndexVM));
        }