Пример #1
0
        public async Task <IActionResult> ExcluirSLA(int id_SLA)
        {
            if (id_SLA < 1)
            {
                return(BadRequest());
            }

            var slaToDelete = _configuracaoContext.SLAItems
                              .OfType <SLAItem>()
                              .SingleOrDefault(c => c.Id_SLA == id_SLA);

            if (slaToDelete is null)
            {
                return(BadRequest());
            }

            _configuracaoContext.SLAItems.Remove(slaToDelete);

            //Create Integration Event to be published through the Event Bus
            var SLAExclusaoEvent = new SLAExclusaoIE(slaToDelete.Id_SLA);

            // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction
            await _configuracaoIntegrationEventService.DeleteEventAndSLAContextChangesAsync(SLAExclusaoEvent);

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

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