public async Task <Result <Product> > Handle(InsertProductCommand request, CancellationToken cancellationToken) { try { using (var connection = _dbConnectionFactory.GetConnection()) { connection.Open(); using (var transaction = connection.BeginTransaction()) { try { var updatedProduct = await connection.QuerySingleOrDefaultAsync <Product>(InsertCommand, request, transaction); return(Result <Product> .Success(updatedProduct)); } catch (Exception exception) { _logger.LogError(exception, "Error occured when inserting product. {@product}", request); transaction.Rollback(); } finally { transaction.Commit(); } } } } catch (Exception exception) { _logger.LogError(exception, "Error occured when operating on the Products table."); } return(Result <Product> .Failure(ErrorCodes.DataAccessError, "Error occured when inserting product.")); }
public async Task <NotificationResult> InsertAsync(InsertProductCommand insertProductCommand) { BeginTransaction(); var result = await _handler.InsertAsync(insertProductCommand); return(Commit(result)); }
public async Task Run( [ServiceBusTrigger("%ServiceBusConfig:WriteTopic%", "%ServiceBusConfig:CreateProductSubscription%", Connection = "ServiceBusConfig:ReadConnectionString", IsSessionsEnabled = true)] Message message, IMessageSession messageSession, string lockToken) { var operation = await _messageReader.GetModelAsync <CreateProductServiceBusMessage>(message); if (!operation.Status) { await messageSession.DeadLetterAsync(lockToken, operation.ErrorCode); return; } var model = operation.Data; var insertProductCommand = new InsertProductCommand(model.CorrelationId, model.ProductCode, model.ProductName); var insertOperation = await _mediator.Send(insertProductCommand); if (!insertOperation.Status) { await messageSession.DeadLetterAsync(lockToken, insertOperation.ErrorCode); return; } await messageSession.CompleteAsync(lockToken); }
public async Task <APIResult> Insert([FromBody] InsertProductCommand command) { var id = await mediator.Send(command); return(new APIResult() { Data = new { id = (id > 0) ? id : (int?)null }, Result = (id > 0) ? 0 : -1, }); }
public async Task <IActionResult> PostAsync([FromBody] InsertProductCommand insertProductCommand) { return(Ok(await _mediator.Send(insertProductCommand))); }
public ProductInfo(InsertProductCommand insertProductCommand) { this.Description = insertProductCommand.Description; }
public async Task <NotificationResult> InsertAsync(InsertProductCommand insertProductCommand) { var product = new ProductInfo(insertProductCommand); return(await _repository.InsertAsync(product)); }
public static ProductEntity Create(InsertProductCommand command) { return(new ProductEntity(default, command.Description));