示例#1
0
        public async Task <IActionResult> AtualizaNomeUsuario(int id_Usuario, string nome_Usuario)
        {
            //AREA DE VALIDACAO
            string msgRule = "";

            if (id_Usuario < 1)
            {
                return(BadRequest());
            }

            //if (!ruleValidaLoginUsuario(nome_Usuario, ref msgRule))
            //{
            //    return BadRequest(msgRule);
            //}

            var usuarioToSave = _usuarioContext.Set <UsuarioItem>().SingleOrDefault(c => c.id_Usuario == id_Usuario);

            if (usuarioToSave is null)
            {
                msgRule = _localizer["UsuarioNaoLocalizado"];
                return(BadRequest(msgRule));
            }
            //FIM AREA DE VALIDACAO

            usuarioToSave.nome_Usuario = nome_Usuario;

            _usuarioContext.UsuarioItems.Update(usuarioToSave);

            //Create Integration Event to be published through the Event Bus
            var usuarioAtualizaLoginEvent = new UsuarioAtualizaLoginIE(usuarioToSave.id_Usuario, usuarioToSave.login_Usuario);

            try
            {
                // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction
                await _usuarioIntegrationEventService.SaveEventAndUsuarioChangesAsync(usuarioAtualizaLoginEvent);
            }
            catch (Exception e)
            {
                //Validações das CONSTRAINTS do BANCO
                if (ruleValidaLoginUsuarioUnique(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 _usuarioIntegrationEventService.PublishThroughEventBusAsync(usuarioAtualizaLoginEvent);

            return(CreatedAtAction(nameof(AtualizaLoginUsuario), null));
        }
        public async Task <IActionResult> SalvarPerfil([FromBody] PerfilItem perfilToSave)
        {
            //AREA DE VALIDACAO
            string msgRule = "";

            if (!ruleValidaNomePerfil(perfilToSave.nome_Perfil, ref msgRule))
            {
                return(BadRequest(msgRule));
            }

            //FIM AREA DE VALIDACAO

            if (_usuarioContext.Set <PerfilItem>().Any(e => e.id_Perfil == perfilToSave.id_Perfil))
            {
                _usuarioContext.PerfilItems.Update(perfilToSave);
            }
            else
            {
                _usuarioContext.PerfilItems.Add(perfilToSave);
            }

            //Create Integration Event to be published through the Event Bus
            var perfilSaveEvent = new PerfilSaveIE(perfilToSave.id_Perfil, perfilToSave.nome_Perfil);

            try
            {
                // Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction
                await _usuarioIntegrationEventService.SaveEventAndPerfilContextChangesAsync(perfilSaveEvent, perfilToSave);
            }
            catch (Exception e)
            {
                //Validações das CONSTRAINTS do BANCO
                if (ruleValidaNomePerfilUnique(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 _usuarioIntegrationEventService.PublishThroughEventBusAsync(perfilSaveEvent);


            return(CreatedAtAction(nameof(SalvarPerfil), perfilToSave.id_Perfil));
        }
示例#3
0
 public void Alterar(params TEntity[] obj)
 {
     _context.Set <TEntity>().UpdateRange(obj);
     _context.SaveChanges();
 }
示例#4
0
 public Base(UsuarioContext _bd)
 {
     this.bd = _bd;
     this.PrimaryDatabaseSet   = bd.Set <TPrimaryEntity>();
     this.DependentDatabaseSet = bd.Set <TDependentEntity>();
 }
示例#5
0
 public virtual void Add(TDomain entity)
 {
     _context.Set <TDomain>().Add(entity);
 }