public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var directSale = await _context.DirectSales.FindAsync(request.Id); if (directSale == null) { throw new RestException(HttpStatusCode.NotFound, new { directsale = "Could not find directsale" }); } ////_context.Database.BeginTransaction(); // Add Integration event to clean the basket directSale.Name = request.Name ?? directSale.Name; directSale.EndDate = request.EndDate ?? directSale.EndDate; directSale.DirectSaleType = request.DirectSaleType ?? directSale.DirectSaleType; var success = await _context.SaveChangesAsync() > 0; if (success) { var _directSalePublishedStartedIntegrationEvent = new DirectSalePublishedIntegrationEvent(request.Id, request.Name, request.DirectSaleType, request.EndDate); await _sellerIntegrationEventService.AddAndSaveEventAsync(_directSalePublishedStartedIntegrationEvent); ////_context.Database.CommitTransaction(); //_sellerIntegrationEventService.PublishEvent(_directSalePublishedStartedIntegrationEvent); return(Unit.Value); } throw new Exception("Problem Saving Changes"); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var directSale = new DirectSale { Id = request.Id, Name = request.Name, EndDate = request.EndDate, DirectSaleType = request.DirectSaleType }; _context.DirectSales.Add(directSale); var success = await _context.SaveChangesAsync() > 0; if (success) { var _directSalePublishedStartedIntegrationEvent = new DirectSalePublishedIntegrationEvent(request.Id, request.Name, request.DirectSaleType, request.EndDate); //await _sellerIntegrationEventService.AddAndSaveEventAsync(_directSalePublishedStartedIntegrationEvent); //_context.Database.CommitTransaction(); _sellerIntegrationEventService.PublishEvent(_directSalePublishedStartedIntegrationEvent); return(Unit.Value); } throw new Exception("Problem Saving Changes"); }