コード例 #1
0
        public void SendEmailGenericCommand()
        {
            mediator.Send(new SendEmailGenericCommand("Hello world!"));

            var lastSentMessage = this.emailSender.GetLastSentMessage(); ;
            Assert.Equal("Hello world!", lastSentMessage);
        }
コード例 #2
0
        public void CreateSampleAggregateCommand_NoResponse()
        {
            var aggregateId = Guid.NewGuid();

            mediator.Send(new CreateSampleAggregateCommand(aggregateId, "Some name"));

            var aggregate = sampleAggregateRepository.Load(aggregateId);

            Assert.Equal("Some name", aggregate.Name);
        }
コード例 #3
0
 public IActionResult PublishAdvert(Guid id, [FromBody] StockItemDto data)
 {
     try
     {
         _command.Send(new PublishAdvertCommand(id, (int)data.Quantity));
         return(new StatusCodeResult((int)HttpStatusCode.Accepted));
     }
     catch (ItemNotFoundException)
     {
         return(NotFound());
     }
     catch (InvalidOperationException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch
     {
         return(NotFound()); // Better a 404 than a potential hack vector.
     }
 }
コード例 #4
0
 public IActionResult Put(Guid id)
 {
     try
     {
         _commandMediator.Send(new StockDisposedCommand(id, GetUserId()));
         return(new StatusCodeResult((int)HttpStatusCode.Accepted));
     }
     catch (System.Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
コード例 #5
0
        public IActionResult Put(Guid id, [FromBody] AdvertDto newState)
        {
            // Set the Id from the URI to the DTO to send on
            if (newState.Id == Guid.Empty)
            {
                newState.Id = id;
            }

            // Ensure the posting user is the advertiserId
            newState.AdvertiserId = GetUserId();

            try
            {
                _commandMediator.Send(CreateCommandForState(newState));
                return(Created($"/api/{GetControllerName()}/{id}", _queryMediator.Get(id)));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #6
0
 public IActionResult PostAdvert(Guid id, [FromBody] PostAdvertPayload data)
 {
     try
     {
         _command.Send(new PostAdvertCommand(id, GetUserId(), data.PublishType == "PublishAndAdd", data.StockQuantity));
         return(new StatusCodeResult((int)HttpStatusCode.Accepted));
     }
     catch (ItemNotFoundException)
     {
         return(NotFound());
     }
     catch (InvalidOperationException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch
     {
         return(NotFound()); // Better a 404 than a potential hack vector.
     }
 }
コード例 #7
0
 public async Task <IProcessResult> Put(UpdateProductInfoCommand command) => await mediator.Send(command);
コード例 #8
0
 public async Task <IProcessResult <int> > Post(CreateAttributeCommand command) => await mediator.Send(command);
コード例 #9
0
ファイル: StockItemController.cs プロジェクト: lulzzz/GoFish
 public void Post([FromBody] StockItemDto item)
 {
     _commandMediator.Send(CreateCommandForState(item));
 }