Exemplo n.º 1
0
        public Alumno Obtener(int id)
        {
            var alumnos = new Alumno();

            try
            {
                using (var ctx = new TestContex())
                {
                    alumnos = ctx.Alumno.Where(x => x.Id == id).SingleOrDefault();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(alumnos);
        }
Exemplo n.º 2
0
 public void Eliminar(int id)
 {
     try
     {
         using (var ctx = new TestContex())
         {
             ctx.Entry(new Alumno {
                 Id = id
             }).State = EntityState.Deleted;
             ctx.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 3
0
        public List <Alumno> Listar()
        {
            var alumnos = new List <Alumno>();

            try
            {
                using (var ctx = new TestContex())
                {
                    alumnos = ctx.Alumno.ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(alumnos);
        }
Exemplo n.º 4
0
 public void Guardar(Alumno alumno)
 {
     try
     {
         using (var ctx = new TestContex())
         {
             //Regitro que ya existe
             if (alumno.Id > 0)
             {
                 ctx.Entry(alumno).State = EntityState.Modified;
             }
             else
             {
                 ctx.Entry(alumno).State = EntityState.Added;
             }
             ctx.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }