public async Task <IActionResult> IncluirSetor([FromBody] SetorItem setorToSave) { Guid gKey; gKey = Guid.NewGuid(); setorToSave.id_Setor = gKey; // Update current setor _setorContext.SetorItems.Add(setorToSave); //if (_settings.UseCache) //{ // Cache<SetorItem> mycache = new Cache<SetorItem>(); // await mycache.SetAsync(cachePrefix + setorToSave.id_Empresa+ setorToSave.id_Setor, setorToSave); //} //Create Integration Event to be published through the Event Bus var setorInclusaoEvent = new SetorInclusaoIntegrationEvent(setorToSave.id_Empresa, setorToSave.id_Setor, setorToSave.nome_Setor); // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction await _setorIntegrationEventService.SaveEventAndSetorContextChangesAsync(setorInclusaoEvent); // Publish through the Event Bus and mark the saved event as published await _setorIntegrationEventService.PublishThroughEventBusAsync(setorInclusaoEvent); return(CreatedAtAction(nameof(IncluirSetor), null)); }