Guest User

EF Reinsert

a guest
Dec 2nd, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.     if (IsPostBack == false)
  4.     {
  5.         long id = Int64.Parse(Request.QueryString["Id"]);
  6.  
  7.         using (var context = new LabContext())
  8.         {
  9.             var request = context.REQUEST.Where(r => r.ID == id).SingleOrDefault<REQUEST>();
  10.  
  11.             var query1 = context.PATIENTTYPE;
  12.             this.PatientType.DataSource = query1.ToList();
  13.             this.PatientType.DataValueField = "ID";
  14.             this.PatientType.DataTextField = "DESCRIPTION";
  15.             this.PatientType.DataBind();
  16.  
  17.             if (request != null)
  18.             {
  19.                 PatientType.SelectedValue = request.PATIENTTYPE.ToString();
  20.             }
  21.         }
  22.     }
  23. }
  24.        
  25. protected void SaveButton_Click(object sender, EventArgs e)
  26. {
  27.     using (var context = new LabContext())
  28.     {
  29.         long id = Int64.Parse(Request.QueryString["Id"]);
  30.         long header = Int64.Parse(Request.QueryString["Header"]);
  31.            
  32.         var request = context.REQUEST.Where(r => r.ID == id).SingleOrDefault<REQUEST>();
  33.         if (request == null)
  34.                 {
  35.                     request = new REQUEST();
  36.                     request.HEADER = header;
  37.                     context.REQUEST.Add(request);
  38.                 }
  39.                
  40.         request.PATIENTTYPE = Int64.Parse(this.PatientType.SelectedValue);
  41.         context.SaveChanges();
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment