Ejemplo n.º 1
0
        /// <summary>
        /// Adiciona, atualiza ou remove usuario de acordo com parametros
        /// </summary>
        /// <param name="usuario">Classe modelo usuario</param>
        /// <param name="crud">add = 0; update = 1; delete = 2</param>
        /// <returns>True para confirmar que gravou no banco</returns>
        public async Task <bool> CRUD(Usuario usuario, int crud)
        {
            Usuario user = new Usuario();

            //Verifica se existe usuario para metodo update/delete
            if (crud != 0)
            {
                user = await GetUsuarioAsync(usuario.Id);

                if (user == null)
                {
                    return(false);
                }
            }

            switch (crud)
            {
            case 0:
                exception = Add(usuario);
                break;

            case 1:
                user.Login      = usuario.Login;
                user.Nascimento = usuario.Nascimento;
                user.Nome       = usuario.Nome;
                user.Perfil     = usuario.Perfil;
                user.Senha      = usuario.Senha;
                user.Cadastro   = usuario.Cadastro;
                exception       = Update(user);
                break;

            case 2:
                exception = Delete(user);
                break;

            default:
                return(false);
            }

            if (exception.Status)
            {
                exception = await SaveChangesAsync();
            }

            if (!exception.Status)
            {
                Erro(new ExceptionFull(
                         System.Reflection.Assembly.GetExecutingAssembly().GetName().Name,
                         GetType().Name,
                         System.Reflection.MethodBase.GetCurrentMethod().Name,
                         exception.Mensagem, exception.Status, DateTime.Now, null)
                     );
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> CrudAsync(Financeiro financeiro, int opcaoCrud)
        {
            if (financeiro == null)
            {
                return(false);
            }

            if (opcaoCrud != 0)
            {
                if (await GetFinanceiroAsync(financeiro.Id) == null)
                {
                    return(false);
                }
            }

            switch (opcaoCrud)
            {
            case 0:
                financeiro.DataRegistro = DateTime.Now;
                _exception = Add(financeiro);
                break;

            case 1:
                _exception = Update(financeiro);
                break;

            case 2:
                _exception = Delete(financeiro);
                break;

            default:
                return(false);
            }

            if (_exception.Status)
            {
                _exception = await SaveChangesAsync();
            }

            if (!_exception.Status)
            {
                Erro(new ExceptionFull(
                         System.Reflection.Assembly.GetExecutingAssembly().GetName().Name,
                         GetType().Name,
                         System.Reflection.MethodBase.GetCurrentMethod().Name,
                         _exception.Mensagem, _exception.Status, DateTime.Now, null
                         ));

                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public void Erro(ExceptionFull exception)
        {
            string sql = "INSERT INTO exceptionfull " +
                         "(Projeto, Classe, Metodo, Mensagem, Status, Data, UsuarioId) " +
                         $"VALUES ({exception.Projeto}, {exception.Classe}, {exception.Metodo}, " +
                         $"{exception.Mensagem}, {exception.Status}, {exception.Data}, {exception.UsuarioId});";

            try
            {
                // _ = _context.Database.ExecuteSqlCommandAsync(sql);
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 4
0
 ExceptionFull IBaseCRUD <T> .Erro(ExceptionFull ExceptionFull)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 5
0
 public void Erro(ExceptionFull exception)
 {
     // _context.Database.ExecuteSqlCommand(exception);
 }