public async Task Inc_SaveModulo()
        {
            //using (var server = CreateServer())
            //{
            IEnumerable <string> Ltoken = await GetAsync();

            for (int i = 6000; i < 7000; i++)
            {
                //var myTestClient = server.CreateClient();

                using (var myTestClient = new HttpClient())
                {
                    ModuloItem moduloItem = new ModuloItem();
                    moduloItem.Nome_Modulo = "TESTE" + i.ToString();        //+ Guid.NewGuid().ToString();
                    var content = new StringContent(JsonConvert.SerializeObject(moduloItem), System.Text.Encoding.UTF8, "application/json");
                    myTestClient.SetBearerToken(((string[])Ltoken)[0]);
                    var response = await myTestClient.PostAsync(Post.SaveModulo(), content);
                }
            }
            //}
        }
        private ArrayList ObtenerModulos(string panel)
        {
            IDataReader modulos = ModulosBD.ObtenerPagina(pagina);
            ArrayList   Modulos = new ArrayList();

            while (modulos.Read())
            {
                if (modulos["NombrePanel"].ToString().ToLower() == panel.ToLower())
                {
                    ModuloItem m = new ModuloItem();
                    m.ModuloTitulo = (string)modulos["ModuloTitulo"];
                    m.ModuloId     = (int)modulos["ModuloId"];
                    m.ModuloDefId  = (int)modulos["ModuloDefId"];
                    m.ModuloOrden  = (int)modulos["ModuloOrden"];
                    Modulos.Add(m);
                }
            }

            modulos.Close();

            return(Modulos);
        }
        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));
        }
 public async Task SaveEventAndModuloContextChangesAsync(IntegrationEvent evt, ModuloItem moduloToSave)
 {
     var strategy = _moduloContext.Database.CreateExecutionStrategy();
     await strategy.ExecuteAsync(async() =>
     {
         using (var transaction = _moduloContext.Database.BeginTransaction())
         {
             try
             {
                 await _moduloContext.SaveChangesAsync();
                 //Tratamento de Identity
                 ((Events.ModuloInclusaoIE)evt).ModuloId = moduloToSave.Id_Modulo;
                 //Tratamento relacionamento
                 ((Events.ModuloInclusaoIE)evt).OperacaoItems            = moduloToSave.OperacaoItems;
                 ((Events.ModuloInclusaoIE)evt).EmpresaPerfilModuloItems = moduloToSave.EmpresaPerfilModuloItems;
                 await _eventLogService.SaveEventAsync(evt, _moduloContext.Database.CurrentTransaction.GetDbTransaction());
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 var sqlException = ex.InnerException as System.Data.SqlClient.SqlException;
                 throw new Exception(sqlException.Number + "::" + sqlException.Message);
             }
         }
     });
 }