public async Task <ProductDto> Register(RegisterProductRequest request) { var command = new RegisterProductCommand(request.Name, request.Cost); var result = await _mediator.Send(command); return(result); }
public async Task Handle(RegisterProductCommand command) { var product = new Product(command.Id, command.Name, command.Description, command.Price); await this._repoProduct.New(product); await this._repoOutbox.New(new Outbox(product.GetType().Name, "New", product)); }
public async Task <IActionResult> RegisterProduct([FromBody] RegisterProductCommandDto model) { RegisterProductCommand command = model.ToDomainCommand(); await _commandDelegator.SendAsync(command); return(Ok()); }
public static Product MapProductCommandToProduct(this RegisterProductCommand command) => new Product { ProductId = command.ProductId, Name = command.Name, Description = command.Description, Price = command.Price, Quantity = command.Quantity };
public async Task <IActionResult> Post([FromBody] ProductPostRequest request) { var productCommand = new RegisterProductCommand(request.Id, request.StockBalance, request.Name, request.Active); // await _mediator.Send(productCommand); var f = await _mediatorHandler.SendCommand(productCommand); return(Ok(f)); }
public void RegisterProduct_ShouldReturnErrorWhenCommandIsInvalid() { // Arrange var productCommand = new RegisterProductCommand("", 0, 0); // Act var result = productCommandHandler.Handle(productCommand, new CancellationToken()); // Assert Assert.False(result.Result); }
public void RegisterProduct_ShouldBeSuccess() { // Arrange var productCommand = new RegisterProductCommand("Pipoca", 10, 5); // Act var result = productCommandHandler.Handle(productCommand, new CancellationToken()); // Assert Assert.True(result.Result); }
public async Task <IActionResult> RegisterAsync([FromBody] RegisterProductCommand productCommand) { //save to db var product = productCommand.MapProductCommandToProduct(); await _productRepository.RegisterProduct(product); //publish event to RabbitMQ var productEvent = productCommand.MapProductCommandToProductRegisteredEvent(); await _rabbitMQPublisher.PublishMessageAsync(productEvent.MessageType, productEvent, ""); return(RedirectToAction("GetByProductId", new { id = product.ProductId })); }
public async Task <IActionResult> Register([FromBody] RegisterProductDto dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var command = new RegisterProductCommand(dto.ProductName); await _registerHandler.HandleAsync(command); return(Ok()); //Http200 }
public static Command Build(string[] data) { Command command; if (int.TryParse(data[0], out _)) { command = new OrderCommand(data); } else { command = new RegisterProductCommand(data); } return(command); }
public async Task HandleAsync(RegisterProductCommand args) { var productName = ProductName .Create(args.ProductName); if (productName.IsSuccess) { var product = new Product(productName.Value); _repository .Add(product); await _unitOfWork .CommitAsync(); } }
public async Task RegisterProduct(RegisterProductCommand command) { try { var message = new HttpRequestBuilder(OcelotApiGatewayAddress) .SetPath("/product") .HttpMethod(HttpMethod.Post) .GetHttpMessage(); var json = JsonConvert.SerializeObject(command); message.Content = new StringContent(json, Encoding.UTF8, "application/json"); await SendRequest <Product>(message); } catch (Exception ex) { } }
public async Task <IActionResult> Save([FromBody] RegisterProductCommand command) { await this._unit.BeginTransaction(); var x = Guid.NewGuid(); Console.WriteLine(x.ToString()); command = new RegisterProductCommand() { Description = "Texte", Name = "XX", Price = 10, Id = x }; await this._commandHandler.Handle(command); await this._unit.Commit(); return(Ok()); }
public void RegisterProduct_ShouldReturnErrorWhenNameIsInvalid() { var command = new RegisterProductCommand("", 10, 5); Assert.False(command.IsValid()); }
public void RegisterProduct_ShouldBeSuccess() { var command = new RegisterProductCommand("Pipoca", 10, 5); Assert.True(command.IsValid()); }
public void RegisterProduct_ShouldReturnErrorWhenPriceIsInvalid() { var command = new RegisterProductCommand("Pipoca", .01m, 5); Assert.False(command.IsValid()); }
public IActionResult Post(RegisterProductCommand obj) { var prod = _mediator.Send(obj); return(Ok(prod)); }
public async Task <IActionResult> RegisterProduct([FromBody] RegisterProductCommand productCommand, [FromServices] IMediator mediator) { await mediator.Send(productCommand); return(Ok()); }
public static ProductRegisteredEvent MapProductCommandToProductRegisteredEvent(this RegisterProductCommand command) => new ProductRegisteredEvent ( Guid.NewGuid(), command.ProductId, command.Name, command.Description, command.Quantity, command.Price );