protected void Insert_Click(object sender, EventArgs e) { using (NMHCDatabaseEntities myEntities = new NMHCDatabaseEntities()) { try { Physician__Patient relation = new Physician__Patient(); relation.CP_ID = cpid; relation.P_ID = pid; relation.UpdatedBy = Profile.UserName; relation.UpdateDateTime = DateTime.Now; relation.UpdateUserName = Profile.Name; myEntities.AddToPhysician__Patient(relation); myEntities.SaveChanges(); } catch (Exception ex) { Notification.Text = ex.Message; } } Response.Redirect(String.Format("~/Hospital/PatientInfo/Physicians.aspx?PID={0}", RegID.Text)); }
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { using (NMHCDatabaseEntities myEntities = new NMHCDatabaseEntities()) { try { if (e.CommandName == "Delete") { string cp_id = ((Literal)e.Item.FindControl("CPID")).Text; Physician__Patient cp = (from r in myEntities.Physician__Patient where (r.CP_ID == cp_id && r.P_ID == pid) select r).SingleOrDefault(); myEntities.DeleteObject(cp); myEntities.SaveChanges(); } Response.Redirect(String.Format("~/Hospital/PatientInfo/Physicians.aspx?PID={0}", pid)); } catch (Exception ex) { //notify = true; //note = ex.Message; } } }