示例#1
0
        protected void grdComics_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //identify
            Int32 ComicID = Convert.ToInt32(grdComics.DataKeys[e.RowIndex].Values["ComicID"]);

            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                Comics track = (from c in db.Comics1
                                where c.ComicID == ComicID
                                select c).FirstOrDefault();

                //delete
                db.Comics1.Remove(track);
                db.SaveChanges();

                //refresh grid
                GetComics();
            }
        }
示例#2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                Comics trac = new Comics();

                Int32 ComicID = 0;

                //check for url
                if (!String.IsNullOrEmpty(Request.QueryString["ComicID"]))
                {
                    //get id from url
                     ComicID = Convert.ToInt32(Request.QueryString["ComicID"]);

                    trac = (from c in db.Comics1
                            where c.ComicID == ComicID
                            select c).FirstOrDefault();
                }

                //fill properties
                trac.Title = txtTitle.Text;
                trac.Author = txtAuthor.Text;
                trac.Publisher = txtPublisher.Text;
                trac.Issue = Convert.ToInt32(txtIssue.Text);

                //no id in the url
                if (ComicID == 0)
                {
                    db.Comics1.Add(trac);
                }

                //save
                db.SaveChanges();

                //redirect
                Response.Redirect("tracker.aspx");
            }
        }
示例#3
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            //connect to db
            using (DefaultConnection db = new DefaultConnection())
            {
                //create new user
                Users objU = new Users();

                //fill the form inputs
                objU.Firstname = txtFirstname.Text;
                objU.Lastname = txtLastname.Text;
                objU.Username = txtUsername.Text;

                //salt and hash text password
                String password = txtPassword.Text;
                String salt = CreateSalt(8);
                String pass_and_salt = password + salt;

                // Create a new instance of the hash crypto service provider.
                HashAlgorithm hashAlg = new SHA256CryptoServiceProvider();

                // Convert the data to hash to an array of Bytes.
                byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(pass_and_salt);

                // Compute the Hash. This returns an array of Bytes.
                byte[] bytHash = hashAlg.ComputeHash(bytValue);

                // Optionally, represent the hash value as a base64-encoded string,
                // For example, if you need to display the value or transmit it over a network.
                string base64 = Convert.ToBase64String(bytHash);

                objU.Password = base64;
                objU.Salt = salt;

                //save
                db.Users1.Add(objU);
                db.SaveChanges();
            }
        }