protected void Button1_Click(object sender, EventArgs e) { entity = new ObjectivesSpecifics(); if (txt_Objetivos.Text != "") { long globalplanId = 0; long teachmodId = long.Parse((string)Session["TeachingModule"]); globalplanId = proxy.GetGlobalPlan(teachmodId); Session["GlobalPlanID"] = globalplanId; try { entity.Number = 1; entity.Description = txt_Objetivos.Text; entity.GlobalPlan = globalplanId; proxy.InsertObjectives(entity); lbl_Mensaje.Text = "ÉXITO. Los datos han sido registrados correctamente."; Componentes1(false); Componentes2(true); } catch (Exception ex) { lbl_Mensaje.Text = "ERROR. Los datos no han sido registrados."; } } }
public void InsertObjectives(ObjectivesSpecifics entity) { using (var context = new QualificationsDBEntities()) { context.ObjectivesSpecifics.Attach(entity); context.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Added); context.SaveChanges(); } }