public List<dtoGMatriculaProfe> c_mProfesXIdForHorario(string idprofe) { try { using (var ctx = new bdsigameEntities()) { string sql = "SELECT DISTINCT `id-grupo` FROM `matricula1` WHERE `id-profesor`= '" + idprofe + "'"; var m = ctx.Database.SqlQuery<string>(sql).ToList(); if (m.Count != 0) { personas per = bd.personas.Where(t => t.id == idprofe).FirstOrDefault(); List<dtoGMatriculaProfe> dss = new List<dtoGMatriculaProfe>(); for (int i = 0; i < m.Count; i++) { dtoG ll = new dtoG(); string g = Convert.ToString(m[i]); grupos n = bd.grupos.Where(t => t.id_grupo == g).FirstOrDefault(); dtoGMatriculaProfe ds = new dtoGMatriculaProfe(); ds.nombres = per.nombres.ToString(); ds.apellidos = per.apellidos.ToString(); ds.año = n.año.ToString(); ds.grado = n.grados.nom_grado.ToString(); ds.id_grupo = n.id_grupo.ToString(); ds.id_profesor = idprofe; ds.f_naci = per.f_naci.ToString(); dss.Add(ds); } return dss; } else { return null; } } } catch (Exception e) { string m = e.Message.ToString(); return null; } }
//-------------------------------------------------------------------------------------------------- public List<dtoGMatriculaProfe> c_mProfesXIdForHorario(string idprofe) { try { // primero consultamos los grupos que tine using (var ctx = new bdsigameEntities()) { string sql = "SELECT DISTINCT `id-grupo` FROM `matricula1` WHERE `id-profesor`= '" + idprofe + "'"; var m = ctx.Database.SqlQuery<string>(sql).ToList(); if (m.Count != 0) { personas per = bd.personas.Where(t => t.id == idprofe).FirstOrDefault(); List<dtoGMatriculaProfe> dss = new List<dtoGMatriculaProfe>(); for (int i = 0; i < m.Count; i++) { dtoG ll = new dtoG(); string g = Convert.ToString(m[i]); grupos n = bd.grupos.Where(t => t.id_grupo == g).FirstOrDefault(); dtoGMatriculaProfe ds = new dtoGMatriculaProfe(); ds.nombres = per.nombres.ToString(); ds.apellidos = per.apellidos.ToString(); ds.año = n.año.ToString(); ds.grado = n.grados.nom_grado.ToString(); ds.id_grupo = n.id_grupo.ToString(); ds.id_profesor = idprofe; ds.f_naci = per.f_naci.ToString(); ds.edad = per.edad.ToString(); dss.Add(ds); } return dss; } else { return null; } } } catch { return null; } // List<matricula1> n = null; // n = bd.matricula1.Where(t => t.id_profesor == idprofe).OrderBy(t => t.grupos.año).ToList(); // List<dtoGMatriculaProfe> d = new List<dtoGMatriculaProfe>(); // if (n.Count != 0) // { // int b = 0; // string codGrupo = null; // string codGrado = null; // foreach (matricula1 item in n) // { // dtoGMatriculaProfe ds = new dtoGMatriculaProfe(); // if (b==0) // { // //Capturo el primer registro para ver que no este repetidos // codGrupo= item.id_grupo.ToString(); // codGrado = item.grupos.grados.nom_grado.ToString(); // ds.nombres = item.personas.nombres.ToString(); // ds.apellidos = item.personas.apellidos.ToString(); // ds.año = item.grupos.año.ToString(); // ds.grado = item.grupos.grados.nom_grado.ToString(); // ds.id_grupo = item.id_grupo.ToString(); // ds.id_profesor = item.personas.id.ToString(); // ds.f_naci = item.personas.f_naci.ToString(); // ds.edad = item.personas.edad.ToString(); // d.Add(ds); // b = 1; // } // else if (b==1) // ya cuando vienes despues verifico a ver si son iguales al primer, si lo son entonces no lo agrego, de lo contrario lo agrego // { // if (codGrupo == item.id_grupo.ToString() && codGrado == item.grupos.grados.nom_grado.ToString()) // { // b = b + 1; // } // else // { // ds.nombres = item.personas.nombres.ToString(); // ds.apellidos = item.personas.apellidos.ToString(); // ds.año = item.grupos.año.ToString(); // ds.grado = item.grupos.grados.nom_grado.ToString(); // ds.id_grupo = item.id_grupo.ToString(); // ds.id_profesor = item.personas.id.ToString(); // ds.f_naci = item.personas.f_naci.ToString(); // ds.edad = item.personas.edad.ToString(); // d.Add(ds); // b = 1; // } // } // } // if (d.Count != 0) // { // return d; // } // else // { // return null; // } // } // else // { // return null; // } //} //catch //{ // return null; //} //=================================== Fin de metodos para filtrar las matriculas de profesores ================ }