public async Task <IActionResult> SalvarItemChecklist([FromBody] ItemChecklistItem itemChecklistToSave) { //AREA DE VALIDACAO string msgRule = ""; if (!ruleValidaNomeItemCheckList(itemChecklistToSave.Nome_ItemChecklist, ref msgRule)) { return(BadRequest(msgRule)); } //FIM AREA DE VALIDACAO if (_configuracaoContext.Set <ItemChecklistItem>().Any(e => e.Id_ItemChecklist == itemChecklistToSave.Id_ItemChecklist)) { _configuracaoContext.ItemChecklistItems.Update(itemChecklistToSave); } else { _configuracaoContext.ItemChecklistItems.Add(itemChecklistToSave); } //Create Integration Event to be published through the Event Bus var itemChecklistSaveEvent = new ItemChecklistSaveIE(itemChecklistToSave.Id_ItemChecklist, itemChecklistToSave.Nome_ItemChecklist); try { // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction await _configuracaoIntegrationEventService.SaveEventAndItemChecklistContextChangesAsync(itemChecklistSaveEvent, itemChecklistToSave); } catch (Exception e) { //Validações das CONSTRAINTS do BANCO if (ruleValidaNomeItemChecklistUnique(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(itemChecklistSaveEvent); return(CreatedAtAction(nameof(SalvarItemChecklist), itemChecklistToSave.Id_ItemChecklist)); }