Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var command = new RegisterOrderCommand
            {
                Customer    = Guid.NewGuid(),
                DeliveryFee = 9,
                Discount    = 30,
                Items       = new List <RegisterOrderItemCommand>
                {
                    new RegisterOrderItemCommand
                    {
                        Product  = Guid.NewGuid(),
                        Quantity = 3
                    }
                }
            };

            GenerateOrder(
                new FakeCustomerRepository(),
                new FakeProductRepository(),
                new FakeOrderRepository(),
                command);

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] RegisterOrderCommand command)
        {
            var customer = User.Identity.Name;
            var result   = _handler.Handle(command);

            return(await Response(result, _handler.Notifications));
        }
Ejemplo n.º 3
0
        static void Main(String[] args)
        {
            Console.WriteLine("DEMO 04 - CUSTOMER");

            Bus.Initialize(configuration =>
            {
                configuration.ReceiveFrom("rabbitmq://localhost/wpc2014/demo04-customer");
                configuration.UseRabbitMqRouting();
                configuration.SetConcurrentConsumerLimit(1);
                configuration.UseJsonSerializer();

                configuration.Subscribe(x => x.Consumer <PaymentRequestHandler>());
            });

            Console.Write("Customer name:");
            var customer = Console.ReadLine();

            var command = new RegisterOrderCommand {
                Customer = customer
            };

            Bus.Instance.Publish(command, x => x.SetResponseAddress(Bus.Instance.Endpoint.Address.Uri));

            Console.ReadLine();
        }
Ejemplo n.º 4
0
        public IActionResult RegisterOrder(OrderViewModel model)
        {
            var registerOrderCommand = new RegisterOrderCommand(model);

            //Send RegisterOrderCommand

            return(View("Thanks"));
        }
Ejemplo n.º 5
0
        public IActionResult RegisterOrder(OrderViewModel model)
        {
            var registerOrderCommand = new RegisterOrderCommand(model);

            rabbitMqManager.SendRegisterOrderCommand(registerOrderCommand);

            return(View("Thanks"));
        }
Ejemplo n.º 6
0
        private static void GenerateOrder(
            ICustomerRepository customerRepository,
            IProductRepository productRepository,
            IOrderRepository orderRepository,
            RegisterOrderCommand command)
        {
            var handler = new OrderCommandHandler(customerRepository, productRepository, orderRepository);

            handler.Handle(command);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> RegisterOrder(OrderViewModel model)
        {
            var registerOrderCommand = new RegisterOrderCommand(model);
            var bus       = BusConfigurator.ConfigureBus();
            var sendToUri = new Uri($"{RabbitMqConstants.RabbitMqUri}{RabbitMqConstants.RegisterOrderServiceQueue}");
            var endPoint  = await bus.GetSendEndpoint(sendToUri);

            await endPoint.Send <FireOnWheels.Messaging.Commands.IRegisterOrderCommand>(
                registerOrderCommand);

            return(View("Thanks"));
        }
Ejemplo n.º 8
0
        public async Task <string> HandleAsync(RegisterOrderCommand command, CancellationToken cancellationToken)
        {
            var transactionId = guidProvider.GenerateGuidString();

            using (var session = documentStore.OpenAsyncSession())
            {
                var transactionDocumentId = DocumentIdHelper.GetDocumentId <OrderTransaction>(documentStore, transactionId);
                var transactionDocument   = new OrderTransaction
                {
                    Id = transactionDocumentId,
                    TransactionStatus = TransactionStatus.NotStarted,
                    LoyaltyPointsConsumptionStepDetails = new StepDetails
                    {
                        Attempts         = 0,
                        RollbackAttempts = 0,
                        StepStatus       = StepStatus.NotStarted
                    },
                    DeliveryCreationStepDetails = new StepDetails
                    {
                        Attempts         = 0,
                        RollbackAttempts = 0,
                        StepStatus       = StepStatus.NotStarted
                    },
                    InventoryReservationStepDetails = new StepDetails
                    {
                        Attempts         = 0,
                        RollbackAttempts = 0,
                        StepStatus       = StepStatus.NotStarted
                    },
                    OrderTotalStepDetails = new OrderTotalStepDetails
                    {
                        Attempts         = 0,
                        RollbackAttempts = 0,
                        StepStatus       = StepStatus.NotStarted,
                        Total            = 0
                    },
                    OrderDetails = new OrderDetails
                    {
                        UserId  = command.UserId,
                        Address = AddressMapper.ToEntity(command.Address),
                        Items   = OrderMapper.ToEntities(command.Order)
                    }
                };

                await session.StoreAsync(transactionDocument, cancellationToken).ConfigureAwait(false);

                await session.SaveChangesAsync().ConfigureAwait(false);
            }

            return(transactionId);
        }
        public void Consume(RegisterOrderCommand commandObj)
        {
            var id = 12;

            Console.WriteLine($"Order with id ${id} registered");
            Console.WriteLine($"Publishing order registered event");

            Console.WriteLine(commandObj.PickupName);

            //notify subscribers that a order is registered
            //var orderRegisteredEvent = new OrderRegisteredEvent(command, id);
            ////publish event
            //rabbitMqManager.SendOrderRegisteredEvent(orderRegisteredEvent);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            var registerOrderCommand = new RegisterOrderCommand(
                new OrderViewModel
            {
                DeliverAddress = "SomeAddr",
                DeliverCity    = "SomeCity",
            });

            using (var rabbitMqManager = new RabbitMqManager())
            {
                //rabbitMqManager.SendRegisterOrderCommand(registerOrderCommand);
            }
            System.Console.ReadLine();
        }
Ejemplo n.º 11
0
        public static void GenerateOrder(
            ICustomerRepository customerRepository,
            IProductRepository productRepository,
            IOrderRepository orderRepository,
            RegisterOrderCommand command)
        {
            var handler = new OrderCommandHandler(customerRepository, productRepository, orderRepository);

            handler.Handle(command);

            if (handler.IsValid())
            {
                System.Console.WriteLine("Customer registrado com sucesso!");
            }
        }
        public OrderHandlerTests()
        {
            _orderItemCommand           = new RegisterOrderItemCommand();
            _orderItemCommand.Id        = Guid.NewGuid();
            _orderItemCommand.ProductId = new Guid("73319ab1-21a7-4fb7-9392-138ea772ef7a");
            _orderItemCommand.Quantity  = 2;

            _orderItemsCommand = new List <RegisterOrderItemCommand>();
            _orderItemsCommand.Add(_orderItemCommand);

            _command             = new RegisterOrderCommand();
            _command.Id          = Guid.NewGuid();
            _command.CustomerId  = new Guid("74d96684-817d-4b5a-8edc-1a20aca2228c");
            _command.DeliveryFee = 5;
            _command.Discount    = 2;
            _command.Items       = _orderItemsCommand.ToArray();
        }
        public async Task <IActionResult> Post([FromBody] RegisterOrderCommand command)
        {
            var result = _handler.Handle(command);

            return(await ResponseAsync(result, _handler.Notifications));
        }
Ejemplo n.º 14
0
 public OrderController(IUow uow, RegisterOrderCommand hadler) : base(uow) => _handler = _handler;
Ejemplo n.º 15
0
 public ICommandResult Post(RegisterOrderCommand command)
 {
     return(_handler.Handle(command));
 }
Ejemplo n.º 16
0
        public static void GenerateOrder(ICustomerRepository customerRepository, IProductRepository productRepository, IOrderRepository orderRepository, RegisterOrderCommand command)
        {
            var handler = new OrderCommandHandler(customerRepository, productRepository, orderRepository);

            handler.Handle(command);

            if (handler.IsValid())
            {
                Console.WriteLine("Your order has been submitted");
            }
        }
Ejemplo n.º 17
0
 public async Task <IActionResult> Post([FromBody] RegisterOrderCommand command) =>
 await Response(_handler.Handle(command), _handler.Notifications);
Ejemplo n.º 18
0
        public static void GenerateOrder(ICustomerRepository customerRepository, IProductRepository productRepository, IOrderRepository orderRepository, RegisterOrderCommand command)
        {
            var handler = new OrderCommandHandler(customerRepository, productRepository, orderRepository);

            handler.Handle(command);

            //Console.WriteLine($"Anterior {mouse.QuantityOnHand} mouse");
            //Console.WriteLine($"Anterior {mousePad.QuantityOnHand} mousePad");
            //Console.WriteLine($"Anterior {teclado.QuantityOnHand} teclado");
            //order.AddItem(new OrderItem(mouse, 2));
            //order.AddItem(new OrderItem(mousePad, 2));
            //order.AddItem(new OrderItem(teclado, 2));
            //Console.WriteLine($"Depois {mouse.QuantityOnHand} mouse");
            //Console.WriteLine($"Depois {mousePad.QuantityOnHand} mousePad");
            //Console.WriteLine($"Depois {teclado.QuantityOnHand} teclado");
        }