public override AddOrderCommand Handle(AddOrderCommand addOrderCommand)
        {
            using (var scope = _ordersDao.BeginTransaction())
            {
                base.logger.DebugFormat(string.Format("Writing new order for customer: {0}", addOrderCommand.CustomerName));
                var inserted = _ordersDao.Add(
                    new Order(
                        customerName: addOrderCommand.CustomerName,
                        orderDescription: addOrderCommand.OrderDescription,
                        dueDate: addOrderCommand.OrderDueDate
                        )
                    );

                scope.Commit();

                addOrderCommand.OrderId = inserted.Id;
            }

            _commandProcessor.Publish(
                new OrderAddedEvent(
                    addOrderCommand.CustomerName,
                    addOrderCommand.OrderDescription,
                    addOrderCommand.OrderDueDate));

            return(base.Handle(addOrderCommand));
        }
示例#2
0
        public override EditOrderCommand Handle(EditOrderCommand editOrderCommand)
        {
            using (var scope = _ordersDao.BeginTransaction())
            {
                Order order = _ordersDao.FindById(editOrderCommand.OrderId);

                order.CustomerName     = editOrderCommand.OrderName;
                order.OrderDescription = editOrderCommand.OrderDescription;
                order.DueDate          = editOrderCommand.OrderDueDate;

                _ordersDao.Update(order);
                scope.Commit();
            }

            return(base.Handle(editOrderCommand));
        }
示例#3
0
 public override CompleteOrderCommand Handle(CompleteOrderCommand completeOrderCommand)
 {
     using (var scope = _ordersDao.BeginTransaction())
     {
         Order order = _ordersDao.FindById(completeOrderCommand.OrderId);
         if (order != null)
         {
             order.CompletionDate = completeOrderCommand.CompletionDate;
             _ordersDao.Update(order);
             scope.Commit();
         }
         else
         {
             throw new ArgumentOutOfRangeException("completeOrderCommand", completeOrderCommand, "Could not find the task to complete");
         }
     }
     return(base.Handle(completeOrderCommand));
 }
示例#4
0
        public override AddOrderCommand Handle(AddOrderCommand addOrderCommand)
        {
            using (var scope = _ordersDao.BeginTransaction())
            {
                var inserted = _ordersDao.Add(
                    new Order(
                        customerName: addOrderCommand.OrderName,
                        orderDescription: addOrderCommand.OrderDescription,
                        dueDate: addOrderCommand.OrderDueDate
                        )
                    );

                scope.Commit();

                addOrderCommand.OrderId = inserted.Id;
            }

            return(base.Handle(addOrderCommand));
        }