public async Task <IActionResult> SalvarSLA([FromBody] SLAItem slaToSave) { string msgRule = ""; if (_configuracaoContext.Set <SLAItem>().Any(e => e.Id_SLA == slaToSave.Id_SLA)) { _configuracaoContext.SLAItems.Update(slaToSave); } else { _configuracaoContext.SLAItems.Add(slaToSave); } //Create Integration Event to be published through the Event Bus var slaSaveEvent = new SLASaveIE(slaToSave.Id_SLA, slaToSave.Id_TipoSituacaoAcomodacao, slaToSave.Id_TipoAtividadeAcomodacao, slaToSave.Id_TipoAcaoAcomodacao, slaToSave.Id_Empresa, slaToSave.Tempo_Minutos, slaToSave.Versao_SLA); try { // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction await _configuracaoIntegrationEventService.SaveEventAndSLAContextChangesAsync(slaSaveEvent, slaToSave); } catch (Exception e) { //Validações das CONSTRAINTS do BANCO if (ruleValidaVersaoUnique(e.Message, ref msgRule)) { return(BadRequest(msgRule)); } else { return(BadRequest(e.Message)); } } // Publish through the Event Bus and mark the saved event as published await _configuracaoIntegrationEventService.PublishThroughEventBusAsync(slaSaveEvent); return(CreatedAtAction(nameof(SalvarSLA), slaToSave.Id_SLA)); }