protected void BoundSubmit_Click(object sender, EventArgs e)
        {
            //use EF to connect to SQL Server
            using (Bounding_SystemEntities db = new Bounding_SystemEntities())
            {

                // Use the Student model to save the new record
                Bound bound = new Bound();
                Int32 BoundID = 0;

                //check the querystring for an id so we can determine add / update
                if (Request.QueryString["BoundID"] != null)
                {
                    //get the id from the url
                    BoundID = Convert.ToInt32(Request.QueryString["BoundID"]);

                    //get the current student from EF
                    bound = (from objB in db.Bounds
                             where objB.bound_id == BoundID
                             select objB).FirstOrDefault();
                }

                // Fill in properties of department
                bound.bound_name = txtBoundName.Text;

                if (DropDownBoundDifficulty.SelectedValue != "-1")
                {
                    bound.bound_difficulty = Convert.ToInt32(DropDownBoundDifficulty.SelectedValue);
                }
                else
                {
                    bound.bound_difficulty = null;
                }

                bound.bound_obstacles = Convert.ToInt32(BoundObstacles.Text);

                //call add only if we have no student ID
                if (BoundID == 0)
                {
                    db.Bounds.Add(bound);
                }

                //run the update or insert
                db.SaveChanges();

                //redirect to the updated students page
                Response.Redirect("bound-archive.aspx");
            }
        }
        protected void grdBoundArchive_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //Identify the DepartmentID to be deleted
            Int32 BoundID = Convert.ToInt32(grdBoundArchive.DataKeys[e.RowIndex].Values["bound_id"]);

            // Connect
            using (Bounding_SystemEntities db = new Bounding_SystemEntities())
            {
                Bound bnd = (from b in db.Bounds
                                  where b.bound_id == BoundID
                                  select b).FirstOrDefault();

                // Delete
                db.Bounds.Remove(bnd);
                db.SaveChanges();

                // Redirect to the departments list page
                GetBoundArchive();
            }
        }
Exemplo n.º 3
0
        protected void btnSubmit_Click(object sender, EventArgs @event)
        {
            using (Bounding_SystemEntities db = new Bounding_SystemEntities())
            {

                Profile profile = new Profile();

                profile.online_name = txtBoundName.Text;
                profile.first_name = txtFirstName.Text;
                profile.last_name = txtLastName.Text;
                profile.server = txtServer.Text;
                profile.age = Convert.ToInt32(txtAge.Text);
                profile.password = PasswordHasher.CreateHash(txtPassword.Text);
                profile.gender = "Unknown";

                db.Profiles.Add(profile);

                db.SaveChanges();
                Response.Redirect("/");

            }
        }