public ResponseModel Guardar() { var rm = new ResponseModel(); try { using (var ctx = new TextContext()) { if (this.Id > 0) { ctx.Entry(this).State = EntityState.Modified; } else { ctx.Entry(this).State = EntityState.Added; } rm.SetResponse(true); ctx.SaveChanges(); } } catch (Exception e) { throw; } return(rm); }
public List <Curso> Todos(int Alumno_id = 0) { var cursos = new List <Curso>(); try { using (var ctx = new TextContext()) { if (Alumno_id > 0) { var cursos_tomados = ctx.AlumnoCurso.Where(x => x.Aumno_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(); } //forma Mas Sencilla //ctx.Database.SqlQuery<Curso>("SELECT c.* FROM Curso c WHERE Id MoT IN(SELECT Curso_Id FROM AlumnoCurso ac WHERE ac.Curso_Id = c.Id AND ac.Alumno_Id = @Alumno_Id ", new SqlParameter("Alumno_Id", Alumno_id)).ToList(); } } catch (Exception e) { throw; } return(cursos); }
public void Eliminar() { try { using (var ctx = new TextContext()) { ctx.Entry(this).State = EntityState.Deleted; ctx.SaveChanges(); } } catch (Exception e) { throw; } }
public List <Alumno> Listar() { var alumnos = new List <Alumno>(); try { using (var ctx = new TextContext()) { alumnos = ctx.Alumno.ToList(); } } catch (Exception e) { throw; } return(alumnos); }
public List <Adjunto> Listar(int Alumno_id) { var adjuntos = new List <Adjunto>(); try { using (var ctx = new TextContext()) { adjuntos = ctx.Adjunto.Where(x => x.Aumno_Id == Alumno_id).ToList(); } } catch (Exception e) { throw; } return(adjuntos); }
public ResponseModel Eliminar() { var rm = new ResponseModel(); try { using (var ctx = new TextContext()) { ctx.Entry(this).State = EntityState.Deleted; rm.SetResponse(true); ctx.SaveChanges(); } } catch (Exception e) { throw; } return(rm); }
public List <AlumnoCurso> Listar(int Aumno_Id) { var alumnocursos = new List <AlumnoCurso>(); try { using (var ctx = new TextContext()) { alumnocursos = ctx.AlumnoCurso .Include("Curso") .Where(x => x.Aumno_Id == Aumno_Id) .ToList(); } } catch (Exception e) { throw; } return(alumnocursos); }
public Alumno Obtener(int id) { var alumnos = new Alumno(); try { using (var ctx = new TextContext()) { alumnos = ctx.Alumno.Include("AlumnoCurso") .Include("AlumnoCurso.Curso") .Where(x => x.Id == id) .SingleOrDefault(); } } catch (Exception e) { throw; } return(alumnos); }