Ejemplo n.º 1
0
        public void CreateDrink(int machineId, DrinkDto drinkDto)
        {
            var machine = _wendingMachineRepository.GetMachineBy();

            machine.Drinks.Add(Mapper.Map <Drink>(drinkDto));
            _wendingMachineRepository.Update(machine);
        }
        public void OrderDrink(int drinkId)
        {
            var machine = _wendingMachineRepository.GetMachineBy();
            var drink   = machine.Drinks.FirstOrDefault(x => x.Id == drinkId);

            if (drink.Count > 0 && machine.Balance >= drink.Price)
            {
                drink.Count--;
                machine.Balance -= drink.Price;
                _wendingMachineRepository.Update(machine);
            }
            else
            {
                throw new ArgumentNullException($"Count of drink {drink.Title} less than 1");
            }
        }