public async Task <IActionResult> SalvarTipoAcaoAcomodacao([FromBody] TipoAcaoAcomodacaoItem tipoAcaoAcomodacaoToSave) { //AREA DE VALIDACAO string msgRule = ""; if (!ruleValidaNomeTipoAcaoAcomodacao(tipoAcaoAcomodacaoToSave.Nome_TipoAcaoAcomodacao, ref msgRule)) { return(BadRequest(msgRule)); } if (!ruleValidaStatusTipoAcaoAcomodacao(tipoAcaoAcomodacaoToSave.Nome_Status, ref msgRule)) { return(BadRequest(msgRule)); } //FIM AREA DE VALIDACAO if (_configuracaoContext.Set <TipoAcaoAcomodacaoItem>().Any(e => e.Id_TipoAcaoAcomodacao == tipoAcaoAcomodacaoToSave.Id_TipoAcaoAcomodacao)) { _configuracaoContext.TipoAcaoAcomodacaoItems.Update(tipoAcaoAcomodacaoToSave); } else { _configuracaoContext.TipoAcaoAcomodacaoItems.Add(tipoAcaoAcomodacaoToSave); } //Create Integration Event to be published through the Event Bus var tipoAcaoAcomodacaoSaveEvent = new TipoAcaoAcomodacaoSaveIE(tipoAcaoAcomodacaoToSave.Id_TipoAcaoAcomodacao, tipoAcaoAcomodacaoToSave.Nome_TipoAcaoAcomodacao, tipoAcaoAcomodacaoToSave.Nome_Status); try { // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction await _configuracaoIntegrationEventService.SaveEventAndTipoAcaoAcomodacaoContextChangesAsync(tipoAcaoAcomodacaoSaveEvent, tipoAcaoAcomodacaoToSave); } catch (Exception e) { //Validações das CONSTRAINTS do BANCO if (ruleValidaNomeTipoAcaoAcomodacaoUnique(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(tipoAcaoAcomodacaoSaveEvent); return(CreatedAtAction(nameof(SalvarTipoAcaoAcomodacao), tipoAcaoAcomodacaoToSave.Id_TipoAcaoAcomodacao)); }
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)); }
public async Task <IActionResult> SalvarSLASituacao([FromBody] SLASituacaoItem slaSituacaoToSave) { string msgRule = ""; if (_configuracaoContext.Set <SLASituacaoItem>().Any(e => e.Id_SLA == slaSituacaoToSave.Id_SLA)) { _configuracaoContext.SLASituacaoItems.Update(slaSituacaoToSave); } else { _configuracaoContext.SLASituacaoItems.Add(slaSituacaoToSave); } //Create Integration Event to be published through the Event Bus var slaSituacaoSaveEvent = new SLASituacaoSaveIE(slaSituacaoToSave.Id_SLA, slaSituacaoToSave.Id_TipoSituacaoAcomodacao, slaSituacaoToSave.Id_Empresa, slaSituacaoToSave.Tempo_Minutos, slaSituacaoToSave.Versao_SLA); try { // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction await _configuracaoIntegrationEventService.SaveEventAndSLASituacaoContextChangesAsync(slaSituacaoSaveEvent, slaSituacaoToSave); } 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(slaSituacaoSaveEvent); return(CreatedAtAction(nameof(SalvarSLASituacao), slaSituacaoToSave.Id_SLA)); }