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); }
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; } }
public List <Alumno> Listar() { var alumnos = new List <Alumno>(); try { using (var ctx = new TestContex()) { alumnos = ctx.Alumno.ToList(); } } catch (Exception) { throw; } return(alumnos); }
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; } }