Пример #1
0
        public ArquiteturaBaseContexto BuscarContexto()
        {
            if (contexto != null)
            {
                return(contexto);
            }

            contexto = new ArquiteturaBaseContexto();

            return(contexto);
        }
Пример #2
0
        public virtual async void AdicionarAsync(T entidade)
        {
            using (_contexto = new ArquiteturaBaseContexto())
            {
                if (_contexto.Database.GetDbConnection().State != ConnectionState.Open)
                {
                    await _contexto.Database.GetDbConnection().OpenAsync();
                }

                _contexto.Set <T>().Add(entidade);

                await _contexto.SaveChangesAsync();

                _contexto.Dispose();
            }
        }
Пример #3
0
        public virtual async void ExcluirAsync(T entidade)
        {
            using (_contexto = new ArquiteturaBaseContexto())
            {
                if (_contexto.Database.GetDbConnection().State != ConnectionState.Open)
                {
                    await _contexto.Database.GetDbConnection().OpenAsync();
                }

                _contexto.Entry(entidade).State = EntityState.Deleted;

                await _contexto.SaveChangesAsync();

                _contexto.Dispose();
            }
        }
Пример #4
0
        public virtual async Task <T> BuscarPorCodigoAsync(long id)
        {
            using (_contexto = new ArquiteturaBaseContexto())
            {
                if (_contexto.Database.GetDbConnection().State != ConnectionState.Open)
                {
                    await _contexto.Database.GetDbConnection().OpenAsync();
                }

                DbSet <T> dbset = _contexto.Set <T>();
                var       obj   = dbset.Find(id);

                _contexto.Dispose();

                return(obj);
            }
        }
Пример #5
0
        public virtual async Task <IEnumerable <T> > BuscarPorCriterioAsync(Expression <Func <T, bool> > where)
        {
            List <T> list;

            using (_contexto = new ArquiteturaBaseContexto())
            {
                if (_contexto.Database.GetDbConnection().State != ConnectionState.Open)
                {
                    await _contexto.Database.GetDbConnection().OpenAsync();
                }

                DbSet <T> dbset = _contexto.Set <T>();
                list = dbset.Where(where).ToListAsync().Result.ToList();

                _contexto.Dispose();
            }
            return(list);
        }
Пример #6
0
        public virtual async Task <IEnumerable <T> > BuscarTodosAsync()
        {
            List <T> list;

            using (_contexto = new ArquiteturaBaseContexto())
            {
                if (_contexto.Database.GetDbConnection().State != ConnectionState.Open)
                {
                    await _contexto.Database.GetDbConnection().OpenAsync();
                }

                DbSet <T> dbset = _contexto.Set <T>();
                list = dbset.ToListAsync().Result.ToList();

                _contexto.Dispose();
            }
            return(list);
        }
Пример #7
0
        public virtual async void ExcluirAsync(Expression <Func <T, bool> > where)
        {
            using (_contexto = new ArquiteturaBaseContexto())
            {
                if (_contexto.Database.GetDbConnection().State != ConnectionState.Open)
                {
                    await _contexto.Database.GetDbConnection().OpenAsync();
                }

                var objetos = _entidade.Where(where).AsEnumerable();
                foreach (var obj in objetos)
                {
                    _contexto.Entry(obj).State = EntityState.Deleted;
                    await _contexto.SaveChangesAsync();
                }
                _contexto.Dispose();
            }
        }