/// <summary>
        /// Sobreescrita de metodo, usando o virtual posso alterar o comportamento deste metodo
        /// sobreescrevendo ele
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public virtual T Add(T entity)
        {
            _baseContexto.Set <T>().Add(entity);

            // Poderia implementar aqui o Padrão UnitOfWork
            _baseContexto.SaveChanges();
            return(entity);
        }
 public async Task <T> GetEntityById(int Id)
 {
     using (var data = new BaseContexto(_optionsBuilder))
     {
         return(await data.Set <T>().FindAsync(Id));
     }
 }
示例#3
0
 public static IEnumerable <UsuarioModel> Listar(this UsuarioModel usuario)
 {
     using (var contexto = new BaseContexto())
     {
         return(contexto.Set <UsuarioModel>());
     }
 }
 public async Task <List <T> > List()
 {
     using (var data = new BaseContexto(_optionsBuilder))
     {
         return(await data.Set <T>().AsNoTracking().ToListAsync());
     }
 }
示例#5
0
 public virtual T Selecionar(int id)
 {
     using (var contexto = new BaseContexto())
     {
         return(contexto.Set <T>().Find(id));
     }
 }
示例#6
0
 public static UsuarioModel Selecionar(this UsuarioModel usuario, int id)
 {
     using (var contexto = new BaseContexto())
     {
         return(contexto.Set <UsuarioModel>().Find(id));
     }
 }
示例#7
0
 public virtual IList <T> Listar()
 {
     using (var contexto = new BaseContexto())
     {
         return(contexto.Set <T>().ToList());
     }
 }
示例#8
0
 public virtual void Incluir(T item)
 {
     using (var contexto = new BaseContexto())
     {
         contexto.Set <T>().Add(item);
         contexto.SaveChanges();
     }
 }
示例#9
0
 public static void Incluir(this UsuarioModel item)
 {
     using (var contexto = new BaseContexto())
     {
         contexto.Set <UsuarioModel>().Add(item);
         contexto.SaveChanges();
     }
 }
 public async Task Update(T Objeto)
 {
     using (var data = new BaseContexto(_optionsBuilder))
     {
         data.Set <T>().Update(Objeto);
         await data.SaveChangesAsync();
     }
 }
示例#11
0
 public static void Deletar(this UsuarioModel item)
 {
     using (var contexto = new BaseContexto())
     {
         contexto.Set <UsuarioModel>().Remove(item);
         contexto.SaveChanges();
     }
 }
示例#12
0
        public override IList <VeiculoModel> Listar()
        {
            using (var contexto = new BaseContexto())
            {
                return(contexto.Set <VeiculoModel>().Include("TipoVeiculo").ToList());
            }

            //return base.Listar(includes);
        }
示例#13
0
 public static IQueryable <UsuarioModel> Listar(this UsuarioModel usuario, params string[] includes)
 {
     using (var contexto = new BaseContexto())
     {
         var query = contexto.Set <UsuarioModel>().AsQueryable();
         foreach (var include in includes)
         {
             query = query.Include(include);
         }
         return(query.AsNoTracking());
     }
 }
示例#14
0
 public virtual IList <T> Listar <TProperty>(params Expression <Func <T, TProperty> >[] includes)
 {
     using (var contexto = new BaseContexto())
     {
         var select = contexto.Set <T>().AsQueryable();
         foreach (var include in includes)
         {
             select = select.Include(include);
         }
         return(select.AsNoTracking().ToList());
     }
 }
 public void InsertUnitOfWork(T obj)
 {
     _context.Set <T>().Add(obj);
 }
示例#16
0
 public void Inserir(TEntidade obj)
 {
     Db.Set <TEntidade>().Add(obj);
     Db.SaveChanges();
 }
示例#17
0
 public BaseRepositorio(BaseContexto context)
 {
     _context = context;
     _dbSet   = context.Set <T>();
 }
示例#18
0
 public Repositorio()
 {
     Db    = new BaseContexto();
     DbSet = Db.Set <T>();
 }