protected void parentSubmit_Click(object sender, EventArgs e) { // connect using (muskokaModel db = new muskokaModel()) { // create guardian login object gaurdian objO = new gaurdian(); String firstname = firstName.Text; String lastname = lastName.Text; objO = (from o in db.gaurdians where o.firstName == firstname && o.lastName == lastname select o).FirstOrDefault(); if (objO != null) { // store the camperID in the session Session["guardianID"] = objO.ID; // redirect to sign in/out page Response.Redirect("Parent/CamperAttendance.aspx?guardianID=" + objO.ID); } else { lblError.Text = "Invalid Login"; } } }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { // get the id from the url Int32 camperID = Convert.ToInt32(Request.QueryString["camperID"]); // connect var conn = new muskokaModel(); // look up the camper var objCamper = (from c in conn.camperProfiles where c.camperID == camperID select c).FirstOrDefault(); var objPayment = (from p in conn.payments where p.camperID == camperID select p).FirstOrDefault(); // run the query using LINQ var payment = (from p in conn.payments where p.camperID == camperID select p); // display the query results in grid view grdPayment.DataSource = payment.ToList(); grdPayment.DataBind(); // populate the camper form familyName.Text = objCamper.familyName; firstName.Text = objCamper.firstName; rate.Text = "$" + objCamper.rate; } }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { // check for url ID if (!String.IsNullOrEmpty(Request.QueryString["camperID"])) { // get the url Int32 camperID = Convert.ToInt32(Request.QueryString["camperID"]); // connect var conn = new muskokaModel(); // look up the camper var objCamper = (from c in conn.camperProfiles where c.camperID == camperID select c).FirstOrDefault(); // populate the form firstName.Text = objCamper.firstName; lastName.Text = objCamper.lastName; rate.Text = objCamper.rate; age.Text = Convert.ToString(objCamper.age); address.Text = objCamper.address; contactName.Text = objCamper.contactName; contactRelation.Text = objCamper.contactRelation; contactNumber.Text = objCamper.contactNumber; impNotes.Text = objCamper.importantNotes; } } }
protected void getCampers() { //connect to db var conn = new muskokaModel(); //run the query using LINQ var Campers = from c in conn.camperProfiles select c; //display the query results in grid view grdCampers.DataSource = Campers.ToList(); grdCampers.DataBind(); }
protected void GetCampers() { using (muskokaModel db = new muskokaModel()) { // store the id from the url in a variable Int32 guardianID = Convert.ToInt32(Request.QueryString["guardianID"]); // look up the campers related to that name var campers = (from c in db.camperProfiles from g in c.gaurdians where g.ID == guardianID select c); grdCampers.DataSource = campers.ToList(); grdCampers.DataBind(); } }
protected void Create_Click(object sender, EventArgs e) { // check if we have an ID for editing Int32 camperID = 0; if (!String.IsNullOrEmpty(Request.QueryString["camperID"])) { camperID = Convert.ToInt32(Request.QueryString["camperID"]); } //connect to db var conn = new muskokaModel(); //use camper class to create a new camper object Models.camperProfile c = new Models.camperProfile(); //fill the properties of the new camper c.firstName = firstName.Text; c.lastName = lastName.Text; c.familyName = familyName.Text; c.rate = rate.Text; c.age = Convert.ToInt32(age.Text); c.address = address.Text; c.contactName = contactName.Text; c.contactRelation = contactRelation.Text; c.contactNumber = contactNumber.Text; c.importantNotes = impNotes.Text; //save the new object to the database if (camperID == 0) { conn.camperProfiles.Add(c); } else { c.camperID = camperID; conn.camperProfiles.Attach(c); conn.Entry(c).State = System.Data.Entity.EntityState.Modified; } conn.SaveChanges(); //redirect to the Index page Response.Redirect("Index.aspx?"); }
protected void submitPayment_Click(object sender, EventArgs e) { Int32 camperID = 0; if (!String.IsNullOrEmpty(Request.QueryString["camperID"])) { camperID = Convert.ToInt32(Request.QueryString["camperID"]); } // connect to db var conn = new muskokaModel(); // use the payment class to create new payment Models.payment p = new Models.payment(); p.date = payCalendar.Text; p.amount = "$" + makePayment.Text; p.payment_type = payType.SelectedItem.Text; p.camperID = Convert.ToInt32(Request.QueryString["camperID"]); if (camperID == 0) { lblPayment.Text = "Cannot Submit Payment"; } else { p.camperID = camperID; conn.payments.Attach(p); conn.Entry(p).State = System.Data.Entity.EntityState.Modified; } conn.SaveChanges(); //redirect Response.Redirect("Pay.aspx"); }
protected void grdCampers_RowDeleting(object sender, GridViewDeleteEventArgs e) { //function to delete a camper from the list of profiles // 1. determine row in the grid Int32 gridIndex = e.RowIndex; // 2. find the camper id value in the selected row Int32 camperID = Convert.ToInt32(grdCampers.DataKeys[gridIndex].Values["camperID"]); // 3. connect to db using (muskokaModel db = new muskokaModel()) { var camp = (from c in db.camperProfiles where c.camperID == camperID select c).FirstOrDefault(); // 4. delete the selected camper db.camperProfiles.Remove(camp); db.SaveChanges(); // 5. referesh the grid getCampers(); } }