/Cap.cs Secret
Created
November 25, 2020 22:31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using DotNetCore.CAP; | |
using Microsoft.AspNetCore.Mvc; | |
using Sales.Contracts; | |
namespace Sales | |
{ | |
public class PlaceOrderController : Controller | |
{ | |
private readonly SalesDbContext _dbContext; | |
private readonly ICapPublisher _publisher; | |
public PlaceOrderController(SalesDbContext dbContext, ICapPublisher publisher) | |
{ | |
_dbContext = dbContext; | |
_publisher = publisher; | |
} | |
[HttpPost("/sales/orders/{orderId:Guid}")] | |
public async Task<IActionResult> Action([FromRoute] Guid orderId) | |
{ | |
using (var transaction = _dbContext.Database.BeginTransaction(_publisher)) | |
{ | |
_dbContext.Orders.Add(new Order | |
{ | |
OrderId = orderId | |
}); | |
await _dbContext.SaveChangesAsync(); | |
var orderPlaced = new OrderPlaced | |
{ | |
OrderId = orderId | |
}; | |
await _publisher.PublishAsync(nameof(OrderPlaced), orderPlaced); | |
await transaction.CommitAsync(); | |
} | |
return NoContent(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment