Exemplo n.º 1
0
 //metodo Eliminar
 public void Eliminar()
 {
     try
     {
         using (var db = new Model_Sistema())
         {
             db.Entry(this).State = EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 2
0
        //Metodo Guardar

        public void Guardar()
        {
            try
            {
                using (var db = new Model_Sistema())
                {
                    if (this.semestre_id > 0)//sis existe un valor mayor a cero es porque existe registro
                    {
                        db.Entry(this).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        //SINO EXISTE EL REGISTRO LO GRABA(nuevo)
                        db.Entry(this).State = System.Data.Entity.EntityState.Added;
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 3
0
 //metodo guardar
 public void Guardar()//retorna solo un objeto
 {
     try
     {
         using (var db = new Model_Sistema())
         {
             if (this.modelo_id > 0)
             {
                 //si existe un valor mayor a 0 es porque existe un registro
                 db.Entry(this).State = EntityState.Modified;
             }
             else
             {
                 //si no existe registro graba(nuevo registro)
                 db.Entry(this).State = EntityState.Added;
             }
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }