public async Task <IActionResult> AddToShoppingCart(int machineId)
        {
            var selectedMachine = await _machineRepository.GetMachineByIdAsync(machineId);

            if (selectedMachine == null || selectedMachine.stock == 0)
            {
                return(NotFound());
            }
            if (selectedMachine.stock != 0)
            {
                machineList.Add(selectedMachine);
                selectedMachine.stock = selectedMachine.stock - 1;

                await _shoppingCart.AddToCartAsync(selectedMachine);

                _machineRepository.UpdateMachineAsync(selectedMachine);
                canuse = true;
            }

            else
            {
                return(NotFound());
            }


            return(RedirectToAction("Index"));
        }
Пример #2
0
        public async Task <ActionResult> Details(int id)
        {
            var machine = await _machineRepository.GetMachineByIdAsync(id);

            return(View(machine));
        }