示例#1
0
        public List <Registro> Listar()
        {
            var regs = new List <Registro>();

            try
            {
                using (var ctx = new TextContext())
                {
                    regs = ctx.registro.ToList();
                }
            }
            catch (Exception e)
            {
                throw;
            }
            return(regs);
        }
示例#2
0
        public Registro Obtener(int id)
        {
            var reg = new Registro();

            try
            {
                using (var ctx = new TextContext())
                {
                    reg = ctx.registro.Where(x => x.id == id).SingleOrDefault();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(reg);
        }
示例#3
0
        public void Eliminar(int id)
        {
            try
            {
                using (var ctx = new TextContext())
                {
                    ctx.Entry(new Registro {
                        id = id
                    }).State = EntityState.Deleted;

                    ctx.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#4
0
 public void Guardar(Registro reg)
 {
     try
     {
         using (var ctx = new TextContext())
         {
             if (reg.id > 0)
             {
                 ctx.Entry(reg).State = EntityState.Modified;
             }
             else
             {
                 ctx.Entry(reg).State = EntityState.Added;
             }
             ctx.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }