コード例 #1
0
ファイル: AuctionFacadeService.cs プロジェクト: pejmanN/Auc
        public long Create(CreateAuctionCommand command)
        {
            long createdId = 0;

            _listener.Subscribe(new ActionEventHandler <AuctionOpened>(a => createdId = a.Id));
            _bus.Dispatch(command);
            return(createdId);
        }
コード例 #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());
        }
コード例 #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;
                }
                }
            }
        }
コード例 #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
     });
 }
コード例 #5
0
        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));
        }
コード例 #6
0
 public void CreateAccount(CreateAccountDto createAccountDto)
 {
     commandBus.Dispatch(new CreateAccountCommand()
     {
         OwnerId = createAccountDto.OwnerId
     });
 }
コード例 #7
0
 public void Dispatch <T>(T command) where T : ICommand
 {
     using (_container.BeginScope())
     {
         _commandBus.Dispatch(command);
     }
 }
コード例 #8
0
        public void DispatchClassCommand()
        {
            ICommandBus  commandBus = GetCommandBus();
            HelloCommand command    = new HelloCommand("Felix");

            commandBus.Dispatch(command);
            Assert.AreEqual("Hello Felix", command.Text);
        }
コード例 #9
0
        public void DispatchCreateUserCommand()
        {
            ICommandBus       commandBus = ComponentContainer.CreateComponent <ICommandBus>();
            CreateUserCommand command    = new CreateUserCommand("Shiori", "987654321");

            commandBus.Dispatch(command);
            Assert.AreEqual("1234", command.CreateResult);
        }
コード例 #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);
        }
コード例 #11
0
 private void RetryDispatch(ICommandMessage commandMessage)
 {
     try
     {
         _commandBus.Dispatch(commandMessage, this);
     }
     catch (Exception e)
     {
         OnFailure(commandMessage, e);
     }
 }
コード例 #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);
        }
コード例 #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());
        }
コード例 #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);
            }
        }
コード例 #15
0
        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));
            }
        }
コード例 #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));
     }
 }
コード例 #18
0
        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);
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #21
0
 public IActionResult CreateStudent(CreateStudentCommand studentVm)
 {
     _bus.Dispatch(studentVm);
     return(View());
 }
コード例 #22
0
 public IActionResult Add([FromBody] AddAnswer command)
 {
     _commandBus.Dispatch(command);
     return(NoContent());
 }
コード例 #23
0
 public void Post([ModelBinder(typeof(ProductModelBinder))] CreateGenericProductCommand command)
 {
     _commandBus.Dispatch(command);
 }
コード例 #24
0
 public void Post(OpenAuctionCommand command)
 {
     _bus.Dispatch(command);
 }
コード例 #25
0
 public IdResponse CreateCategory(CreateCategoryCommand command)
 {
     return(_bus.Dispatch <CreateCategoryCommand, IdResponse>(command));
 }
コード例 #26
0
 public string Post(CreateAccountCommand command)
 {
     // eventBus.Subscribe<CustomerCreatedEvent>
     commandbus.Dispatch(command);
     return("OK");
 }
コード例 #27
0
 public void RegisterWine(Model.Dtos.RegisterWine registerWine)
 {
     _commandBus.Dispatch(new RegisterWine().From(registerWine));
 }
コード例 #28
0
        public async Task <IActionResult> CreateProductWithReturn([FromServices] ICommandBus commandBus, [FromBody] CreateProductCommand command, CancellationToken cancellationToken)
        {
            await commandBus.Dispatch(command, cancellationToken);

            return(Ok());
        }
コード例 #29
0
 public void Post([FromBody] OpenAuctionCommand command)
 {
     _bus.Dispatch(command);
 }
コード例 #30
0
 public IActionResult Create([FromBody] CreateQuestion command)
 {
     _bus.Dispatch(command);
     return(NoContent());
 }