Exemplo n.º 1
0
        public long Create(CreateAuctionCommand command)
        {
            long createdId = 0;

            _listener.Subscribe(new ActionEventHandler <AuctionOpened>(a => createdId = a.Id));
            _bus.Dispatch(command);
            return(createdId);
        }
Exemplo n.º 2
0
        public ActionResult Save(CreateInvoiceSaleCommand model)
        {
            model.Children.Add(new InvoiceSaleChild(0, 100, 1, 2000));
            model.Children.Add(new InvoiceSaleChild(0, 101, 2, 5000));

            Bus.Dispatch(model);
            return(View());
        }
Exemplo n.º 3
0
        public void Execute(SelectGoodsTypeQuery command, CommandType commandtype, string usersave)
        {
            if (command != null)
            {
                switch (commandtype)
                {
                case CommandType.Create:
                {
                    var obj = new CreateGoodsTypeCommand()
                    {
                        TypeTitle = command.TypeTitle,
                        ParentId  = command.ParentId,
                        UserSave  = usersave
                    };
                    foreach (var itm in command.Goodsgroups)
                    {
                        obj.Goodsgroup.Add(new CreateGoodsGroupCommand()
                            {
                                GoodsTypeId = itm.Id,
                                GroupTitle  = itm.GroupTitle,
                                ParentId    = itm.ParentId
                            });
                    }

                    _bus.Dispatch(obj);
                    break;
                }

                case CommandType.Update:
                {
                    var obj = new UpdateGoodsTypeCommand()
                    {
                        Id        = command.Id,
                        TypeTitle = command.TypeTitle,
                        ParentId  = command.ParentId,
                        UserSave  = usersave
                    };
                    _bus.Dispatch(obj);
                    break;
                }

                case CommandType.Delete:
                {
                    var obj = new DeleteGoodsTypeCommand()
                    {
                        Id        = command.Id,
                        TypeTitle = command.TypeTitle,
                        ParentId  = command.ParentId,
                        UserSave  = usersave
                    };
                    _bus.Dispatch(obj);
                    break;
                }
                }
            }
        }
Exemplo n.º 4
0
 public async Task Create(EstateViewModel model)
 {
     await _bus.Dispatch(new CreateEstateCommand
     {
         Address   = model.Address,
         Area      = model.Area,
         Direction = model.Direction,
         Name      = model.Name,
         OwnerId   = model.OwnerId
     });
 }
        public async Task <IActionResult> CreateProduct(CreateProductCommand command)
        {
            var id = 0;

            _eventListener.Subscribe(new ActionHandler <EntityCreated>(a =>
            {
                id = a.Id;
            }));

            await _bus.Dispatch(command);

            return(Ok(id));
        }
Exemplo n.º 6
0
 public void CreateAccount(CreateAccountDto createAccountDto)
 {
     commandBus.Dispatch(new CreateAccountCommand()
     {
         OwnerId = createAccountDto.OwnerId
     });
 }
 public void Dispatch <T>(T command) where T : ICommand
 {
     using (_container.BeginScope())
     {
         _commandBus.Dispatch(command);
     }
 }
Exemplo n.º 8
0
        public void DispatchClassCommand()
        {
            ICommandBus  commandBus = GetCommandBus();
            HelloCommand command    = new HelloCommand("Felix");

            commandBus.Dispatch(command);
            Assert.AreEqual("Hello Felix", command.Text);
        }
Exemplo n.º 9
0
        public void DispatchCreateUserCommand()
        {
            ICommandBus       commandBus = ComponentContainer.CreateComponent <ICommandBus>();
            CreateUserCommand command    = new CreateUserCommand("Shiori", "987654321");

            commandBus.Dispatch(command);
            Assert.AreEqual("1234", command.CreateResult);
        }
Exemplo n.º 10
0
        public Guid Post(CreateDimensionCommand command)
        {
            var id = Guid.Empty;

            this._listener.Subscribe(new ActionHandler <DimensionCreated>(a =>
            {
                id = a.Id;
            }));
            _commandBus.Dispatch(command);
            return(id);
        }
 private void RetryDispatch(ICommandMessage commandMessage)
 {
     try
     {
         _commandBus.Dispatch(commandMessage, this);
     }
     catch (Exception e)
     {
         OnFailure(commandMessage, e);
     }
 }
Exemplo n.º 12
0
        public Task Handle(PartyConfirmed message, IMessageHandlerContext context)
        {
            var command = new CreateParticipantCommand
            {
                Id   = message.PartyId,
                Name = message.Name
            };

            _commandBus.Dispatch(command);
            return(Task.CompletedTask);
        }
Exemplo n.º 13
0
        ValueTask IMessageReceiver.Message(DataMessage oDataMessage)
        {
            var sCommandName = oDataMessage.Data.Type;
            var sCommandData = oDataMessage.Data.Attributes;

            // var oCommandType = _oCommandMapper.GetCommandTypeByName(sCommandName);
            var oCommand = _oCommandMapper.ToCommand(sCommandName, sCommandData);

            _oCommandBus.Dispatch(oCommand);

            return(new ValueTask());
        }
Exemplo n.º 14
0
        public void DispatchMixedInterfaceCommand()
        {
            ICommandBus commandBus = GetCommandBus();

            for (int i = 1; i < 11; i++)
            {
                User user = new User(i, i * 10);
                commandBus.Dispatch(user);
                Assert.AreEqual($"UserOf{i}", user.UserName);
                Assert.AreEqual($"RoleOf{i * 10}", user.RoleName);
            }
        }
        public async Task <IActionResult> Post(CreateLetterCommand command)
        {
            try
            {
                var userId = this.User.Claims.FirstOrDefault(x => x.Type == "sub")?.Value;
                var result = await _bus.Dispatch(command);

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.ExpectationFailed, e.Message));
            }
        }
Exemplo n.º 16
0
        public Guid RegisterCustomer(RegisterCustomerCommand registerCustomerCommand)
        {
            Guid customerId = Guid.Empty;

            eventBus.Subscribe(new ActionHandler <CustomerCreatedEvent>(p =>
                                                                        customerId = p.CustomerId
                                                                        ));

            var opt = new TransactionOptions();

            opt.IsolationLevel = IsolationLevel.ReadCommitted;
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, opt))//AOP =>use PostSharp Or Castle Interceptor
            {
                commandbus.Dispatch(registerCustomerCommand);
                commandbus.Dispatch(new CreateAccountCommand()
                {
                    OwnerId = customerId
                });
                scope.Complete();
                eventBus.Publish(new TransactionCommitedEvent());
            }
            return(customerId);
        }
 protected IActionResult Dispatch(ICommand command)
 {
     try
     {
         commandBus.Dispatch(command);
         return(StatusCode(200));
     }
     catch (System.Exception Exception)
     {
         HttpResponse response  = (new FailureResponseCreator(Exception)).Create();
         object       ErrorData = jsonApiEncoder.EncodeError(response);
         return(StatusCode(response.Code, ErrorData));
     }
 }
        public void Create()
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder
            .RegisterCommandBusComponents()
            .RegsiterCommandHandlers(this.GetType().Assembly);
            var container = builder.Build();

            ICommandBus bus = container.Resolve <ICommandBus>();
            MyCommand   cmd = new MyCommand();

            bus.Dispatch(cmd);
            Assert.AreEqual("A", cmd.AResult);
            Assert.AreEqual("B", cmd.BResult);
        }
Exemplo n.º 19
0
        public HttpResponseMessage PostListing([FromBody] RealtorListing realtorListing)
        {
            var listingId   = Guid.NewGuid();
            var postListing = new PostListing(
                listingId,
                realtorListing.NumberOfBathrooms,
                realtorListing.NumberOfBedrooms,
                realtorListing.YearBuilt,
                realtorListing.Street,
                realtorListing.City,
                realtorListing.State,
                realtorListing.Zip,
                realtorListing.Price);

            try
            {
                _commandBus.Dispatch(postListing);
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
            }
            return(Request.CreateResponse(HttpStatusCode.Created, postListing));
        }
Exemplo n.º 20
0
        public async Task <ActionResult <Guid> > CreateProductWithReturn([FromServices] ICommandBus commandBus, [FromBody] CreateProductWithReturnCommand command, CancellationToken cancellationToken)
        {
            var response = await commandBus.Dispatch(command, cancellationToken);

            return(Ok(response));
        }
Exemplo n.º 21
0
 public IActionResult CreateStudent(CreateStudentCommand studentVm)
 {
     _bus.Dispatch(studentVm);
     return(View());
 }
Exemplo n.º 22
0
 public IActionResult Add([FromBody] AddAnswer command)
 {
     _commandBus.Dispatch(command);
     return(NoContent());
 }
Exemplo n.º 23
0
 public void Post([ModelBinder(typeof(ProductModelBinder))] CreateGenericProductCommand command)
 {
     _commandBus.Dispatch(command);
 }
Exemplo n.º 24
0
 public void Post(OpenAuctionCommand command)
 {
     _bus.Dispatch(command);
 }
Exemplo n.º 25
0
 public IdResponse CreateCategory(CreateCategoryCommand command)
 {
     return(_bus.Dispatch <CreateCategoryCommand, IdResponse>(command));
 }
Exemplo n.º 26
0
 public string Post(CreateAccountCommand command)
 {
     // eventBus.Subscribe<CustomerCreatedEvent>
     commandbus.Dispatch(command);
     return("OK");
 }
Exemplo n.º 27
0
 public void RegisterWine(Model.Dtos.RegisterWine registerWine)
 {
     _commandBus.Dispatch(new RegisterWine().From(registerWine));
 }
Exemplo n.º 28
0
        public async Task <IActionResult> CreateProductWithReturn([FromServices] ICommandBus commandBus, [FromBody] CreateProductCommand command, CancellationToken cancellationToken)
        {
            await commandBus.Dispatch(command, cancellationToken);

            return(Ok());
        }
Exemplo n.º 29
0
 public void Post([FromBody] OpenAuctionCommand command)
 {
     _bus.Dispatch(command);
 }
Exemplo n.º 30
0
 public IActionResult Create([FromBody] CreateQuestion command)
 {
     _bus.Dispatch(command);
     return(NoContent());
 }