public async Task <IActionResult> SalvarModulo([FromBody] ModuloItem moduloToSave)
        {
            if (_moduloContext.Set <ModuloItem>().Any(e => e.Id_Modulo == moduloToSave.Id_Modulo))
            {
                _moduloContext.ModuloItems.Update(moduloToSave);
            }
            else
            {
                _moduloContext.ModuloItems.Add(moduloToSave);
            }

            //Create Integration Event to be published through the Event Bus
            var moduloInclusaoEvent = new ModuloInclusaoIE(moduloToSave.Id_Modulo, moduloToSave.Nome_Modulo);

            // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction
            await _moduloIntegrationEventService.SaveEventAndModuloContextChangesAsync(moduloInclusaoEvent, moduloToSave);

            // Publish through the Event Bus and mark the saved event as published
            await _moduloIntegrationEventService.PublishThroughEventBusAsync(moduloInclusaoEvent);


            return(CreatedAtAction(nameof(SalvarModulo), moduloToSave.Id_Modulo));
        }
Esempio n. 2
0
        public async Task <IActionResult> SalvarEmpresaPerfilModulo([FromBody] EmpresaPerfilModuloItem empresaPerfilModuloToSave)
        {
            if (_moduloContext.Set <EmpresaPerfilModuloItem>().Any(e => e.Id_Empresa == empresaPerfilModuloToSave.Id_Empresa && e.Id_Perfil == empresaPerfilModuloToSave.Id_Perfil && e.Id_Modulo == empresaPerfilModuloToSave.Id_Modulo))
            {
                _moduloContext.EmpresaPerfilModuloItems.Update(empresaPerfilModuloToSave);
            }
            else
            {
                _moduloContext.EmpresaPerfilModuloItems.Add(empresaPerfilModuloToSave);
            }

            //Create Integration Event to be published through the Event Bus
            var empresaPerfilModuloInclusaoEvent = new EmpresaPerfilModuloInclusaoIE(empresaPerfilModuloToSave.Id_Empresa, empresaPerfilModuloToSave.Id_Perfil, empresaPerfilModuloToSave.Id_Modulo);

            // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction
            await _moduloIntegrationEventService.SaveEventAndEmpresaPefilModuloContextChangesAsync(empresaPerfilModuloInclusaoEvent);

            // Publish through the Event Bus and mark the saved event as published
            await _moduloIntegrationEventService.PublishThroughEventBusAsync(empresaPerfilModuloInclusaoEvent);


            return(CreatedAtAction(nameof(SalvarEmpresaPerfilModulo), null));
        }