From 33335eb2309fd14d25c453f6f7362d69d4740eb4 Mon Sep 17 00:00:00 2001 From: dsanz Date: Thu, 16 Mar 2017 16:08:55 +0100 Subject: [PATCH] Change in integration event publication fow as agreed. Flow is 1- start transaction 2- modify catalog iin db 3- add event to db 4- close transaction 5- publish event 6- update event state in db --- .../Controllers/CatalogController.cs | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs index 56629550b..9c3bd170e 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -144,12 +144,20 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers { var oldPrice = item.Price; item.Price = value.Price; - _context.CatalogItems.Update(item); - await _context.SaveChangesAsync(); var @event = new ProductPriceChangedEvent(item.Id, item.Price, oldPrice); - await ProcessEventAsync(@event); + var eventLogEntry = new IntegrationEventLogEntry(@event); + _context.IntegrationEventLog.Add(eventLogEntry); + + await _context.SaveChangesAsync(); + + _eventBus.Publish(@event); + + eventLogEntry.TimesSent++; + eventLogEntry.State = EventStateEnum.Published; + _context.IntegrationEventLog.Update(eventLogEntry); + await _context.SaveChangesAsync(); } return Ok(); @@ -164,17 +172,5 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers return items; } - - private async Task ProcessEventAsync(IntegrationEvent @event) - { - _eventBus.Publish(@event); - var eventLogEntry = new IntegrationEventLogEntry(@event); - eventLogEntry.TimesSent++; - eventLogEntry.State = EventStateEnum.Published; - - _context.IntegrationEventLog.Add(eventLogEntry); - await _context.SaveChangesAsync(); - - } } }