Example #1
0
 public void Eliminar(int id)
 {
     try
     {
         using (var ctx = new NetFramWorkContext())
         {
             ctx.Entry(new Alumno {
                 id = id
             }).State = EntityState.Deleted;
             ctx.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Example #2
0
        public List <Alumno> listar()
        {
            var alumnos = new List <Alumno>();

            try
            {
                using (var ctx = new NetFramWorkContext())
                {
                    alumnos = ctx.Alumno.ToList();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(alumnos);
        }
Example #3
0
        public List <Curso> Todo()
        {
            var cursos = new List <Curso>();

            try
            {
                using (var context = new NetFramWorkContext())
                {
                    cursos = context.Curso.ToList();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            return(cursos);
        }
Example #4
0
        public Alumno Obtener(int id)
        {
            var alumno = new Alumno();

            try {
                using (var ctx = new NetFramWorkContext())
                {
                    alumno = ctx.Alumno
                             .Include("Cursos")
                             .Where(x => x.id == id)
                             .Single();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(alumno);
        }
Example #5
0
        public void Guardar()
        {
            try
            {
                using (var context = new NetFramWorkContext())
                {
                    if (this.id == 0)
                    {
                        context.Entry(this).State = EntityState.Added;
                    }
                    else
                    {
                        context.Database.ExecuteSqlCommand(
                            "DELETE FROM AlumnoCurso WHERE Alumno_id = @id",
                            new SqlParameter("id", this.id)
                            );

                        var cursoBK = this.Cursos;

                        this.Cursos = null;
                        context.Entry(this).State = EntityState.Modified;
                        this.Cursos = cursoBK;
                    }

                    foreach (var c in this.Cursos)
                    {
                        context.Entry(c).State = EntityState.Unchanged;
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }