コード例 #1
0
        public ICommandResult Handle(NewBasket command)
        {
            // Instancia o cliente (Lendo do repositorio)
            var client = _clientRepository.GetById(command.ClientId);

            //listar itens
            List <OrderItem> items = new List <OrderItem>();

            // Gera um novo pedido
            var order = new Order(client);

            foreach (var item in command.Items)
            {
                //Instancia o disk(Lendo do repositorio)
                var disk = _diskRepository.GetById(item.DiskId);
                order.AddOrderItem(new OrderItem(disk, item.UnitPrice, item.Quantity));
            }



            //gerar cashback
            var cashback = _cashBackService.CalculateOrderCashBack(order);

            // Adiciona as notificações do Pedido no Handler
            AddNotifications(order.Notifications);

            // Persiste no banco
            if (Valid)
            {
                _orderRepository.AddAndSave(order, cashback);
            }
            return(new OrderResult(order.Number));
        }