Пример #1
0
 public List <T> Listar()
 {
     using (var ctx = new GestorContext())
     {
         return(ctx.Set <T>().ToList());
     }
 }
Пример #2
0
 public async Task <List <T> > ListarAsync()
 {
     using (var ctx = new GestorContext())
     {
         return(await ctx.Set <T>().ToListAsync <T>());
     }
 }
Пример #3
0
 public T Buscar(int id)
 {
     using (var ctx = new GestorContext())
     {
         return(ctx.Set <T>().Find(id));
     }
 }
Пример #4
0
 public Retorno Excluir(Guid id)
 {
     try
     {
         using (var ctx = new GestorContext())
         {
             var obj = ctx.Set <T>().Find(id);
             ctx.Set <T>().Remove(obj);
             ctx.SaveChanges();
             return(new Retorno("Registro excluido."));
         }
     }
     catch (Exception ex)
     {
         return(new Retorno(ex));
     }
 }
Пример #5
0
        public Retorno Incluir(T obj)
        {
            var retorno = new Retorno();

            try
            {
                using (var ctx = new GestorContext())
                {
                    ctx.Set <T>().Add(obj);
                    int ret = ctx.SaveChanges();
                    return(retorno.Ok("Incluido com sucesso."));
                }
            }
            catch (Exception ex) { return(new Retorno(ex)); }
        }
Пример #6
0
        public async Task <Retorno> IncluirAsync(T obj, Type objetoclass = null)
        {
            var retorno = new Retorno();

            try
            {
                using (var ctx = new GestorContext())
                {
                    ctx.Set <T>().Add(obj);
                    int ret = await ctx.SaveChangesAsync();

                    return(retorno.Ok("Incluido com sucesso."));
                }
            }
            catch (Exception ex) { return(new Retorno(ex)); }
        }
Пример #7
0
        public Retorno IncluirRanger(List <T> obj)
        {
            var retorno = new Retorno();

            try
            {
                using (var ctx = new GestorContext())
                {
                    //obj.ForEach(peditens=> {
                    //    ctx.Set<T>().Add(peditens);
                    //    int ret = ctx.SaveChanges();
                    //});
                    ctx.Set <T>().AddRange(obj);
                    int ret = ctx.SaveChanges();
                    return(retorno.Ok("Incluidos com sucesso."));
                }
            }
            catch (Exception ex) { return(retorno.Error(ex)); }
        }
Пример #8
0
        public Retorno Alterar(T obj)
        {
            var retorno = new Retorno();

            try
            {
                using (var ctx = new GestorContext())
                {
                    ctx.Set <T>().Update(obj);
                    ctx.SaveChanges();
                    retorno.Codigo   = 1;
                    retorno.Mensagem = "Alterado com sucesso.";
                }
            }
            catch (Exception ex)
            {
                retorno.Mensagem = ex.InnerException != null ? $"Erro: {ex.InnerException.Message}, {ex.Message}"
                    : $"Erro: {ex.Message}";
            }

            return(retorno);
        }
 public BaseRepository(GestorContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }