public ResponseModel Guardar() { var rm = new ResponseModel(); try { using (var ctx = new TetsContext()) { if (this.id > 0) { ctx.Entry(this).State = EntityState.Modified; } else { ctx.Entry(this).State = EntityState.Added; } rm.SetResponse(true); ctx.SaveChanges(); } } catch (Exception exception) { throw; } return(rm); }
public List <Curso> Todos(int Alumno_id = 0) { var cursos = new List <Curso>(); try { using (var ctx = new TetsContext()) { if (Alumno_id > 0) { var cursos_tomados = ctx.AlumnoCurso.Where(x => x.Alumno_id == Alumno_id) .Select(x => x.Curso_id) .ToList(); cursos = ctx.Curso.Where(x => !cursos_tomados.Contains(x.id)).ToList(); } else { cursos = ctx.Curso.ToList(); } } } catch (Exception Exception) { throw; } return(cursos); }
public void Eliminar() { try { using (var ctx = new TetsContext()) { ctx.Entry(this).State = EntityState.Deleted; ctx.SaveChanges(); } } catch (Exception exception) { throw; } }
public List <Adjunto> Listar(int Alumno_id) { var adjuntos = new List <Adjunto>(); try { using (var ctx = new TetsContext()) { adjuntos = ctx.Adjunto.Where(x => x.Alumno_id == Alumno_id) .ToList(); } } catch (Exception exception) { throw; } return(adjuntos); }
public List <AlumnoCurso> Listar(int Alumno_id) { var alumnocursos = new List <AlumnoCurso>(); try { using (var ctx = new TetsContext()) { alumnocursos = ctx.AlumnoCurso.Include("Curso") .Where(x => x.Alumno_id == Alumno_id) .ToList(); } } catch (Exception exception) { throw; } return(alumnocursos); }
public Alumno Obtener(int id) { var alumno = new Alumno(); try { using (var ctx = new TetsContext()) { alumno = ctx.Alumno.Include("AlumnoCurso") .Include("AlumnoCurso.Curso") .Where(x => x.id == id) .SingleOrDefault(); } } catch (Exception exception) { throw; } return(alumno); }
public AnexGRIDResponde Listar(AnexGRID grid) { try { using (var ctx = new TetsContext()) { grid.Inicializar(); var query = ctx.Alumno.Where(x => x.id > 0); // Ordenamiento if (grid.columna == "id") { query = grid.columna_orden == "DESC" ? query.OrderByDescending(x => x.id) : query.OrderBy(x => x.id); } if (grid.columna == "Nombre") { query = grid.columna_orden == "DESC" ? query.OrderByDescending(x => x.Nombre) : query.OrderBy(x => x.Nombre); } if (grid.columna == "Sexo") { query = grid.columna_orden == "DESC" ? query.OrderByDescending(x => x.Sexo) : query.OrderBy(x => x.Sexo); } if (grid.columna == "FechaNacimiento") { query = grid.columna_orden == "DESC" ? query.OrderByDescending(x => x.FechaNacimiento) : query.OrderBy(x => x.FechaNacimiento); } var alumnos = query.Skip(grid.pagina) .Take(grid.limite) .ToList(); var total = query.Count(); grid.SetData( from a in alumnos select new { a.id, a.Nombre, a.Sexo, a.FechaNacimiento }, total ); } } catch (Exception E) { throw; } return(grid.responde()); }