public async Task <IActionResult> SalvarChecklist([FromBody] ChecklistItem checklistToSave) { //AREA DE VALIDACAO string msgRule = ""; if (!ruleValidaNomeCheckList(checklistToSave.Nome_Checklist, ref msgRule)) { return(BadRequest(msgRule)); } //FIM AREA DE VALIDACAO if (_configuracaoContext.Set <ChecklistItem>().Any(e => e.Id_Checklist == checklistToSave.Id_Checklist)) { _configuracaoContext.ChecklistItems.Update(checklistToSave); } else { _configuracaoContext.ChecklistItems.Add(checklistToSave); } //Create Integration Event to be published through the Event Bus var checklistSaveEvent = new ChecklistSaveIE(checklistToSave.Id_Checklist, checklistToSave.Nome_Checklist); try { // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction await _configuracaoIntegrationEventService.SaveEventAndChecklistContextChangesAsync(checklistSaveEvent, checklistToSave); } catch (Exception e) { //Validações das CONSTRAINTS do BANCO if (ruleValidaNomeChecklistUnique(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(checklistSaveEvent); return(CreatedAtAction(nameof(SalvarChecklist), checklistToSave.Id_Checklist)); }