public void SaveNewContactToRepository()
        {
            // arrange

            // note connection string is in app.config
            Contact con = new Contact();
            ContactsDb db = new ContactsDb();
            con.fname = "Adam";
            con.lname = "VandenElzen";
            con.phone = "867-5309";
            db.Contacts.AddObject(con);

            // act
            db.SaveChanges();

            // Assert -- see if the record retreived from the database matches the one i just added
            Contact savedContact = (from d in db.Contacts where d.id == con.id select d).Single();

            Assert.AreEqual(savedContact.fname, con.fname);
            Assert.AreEqual(savedContact.lname, con.lname);
            Assert.AreEqual(savedContact.phone, con.phone);

            // cleanup
            db.Contacts.DeleteObject(con);
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            int idToupdate = Convert.ToInt32(Request.QueryString["id"].ToString());
               ContactsDb db = new ContactsDb();
               Contact con = db.Contacts.SingleOrDefault(p =>  p.id == idToupdate);

               con.phone = TextBox1.Text;
               db.SaveChanges();

               Label4.Text = "Contact updated Successfully";
        }
        public void ContactsRepositoryContainsData()
        {
            // arrange
            // note connection string is in app.config
            ContactsDb db = new ContactsDb();

            // act -- go get the first record
            Contact savedContact = (from d in db.Contacts where d.id == 1 select d).Single();

            // assert
            Assert.AreEqual(savedContact.id, 1);
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            if (CheckBox1.Checked == true)
            {
                //delete this contact
                int idToupdate = Convert.ToInt32(Request.QueryString["id"].ToString());
                ContactsDb db = new ContactsDb();
                Contact con = db.Contacts.SingleOrDefault(p => p.id == idToupdate);

                db.Contacts.DeleteObject(con);
                db.SaveChanges();
                Response.Redirect("default.aspx");
            }
            return;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                if (Request.QueryString["id"] == null)
                {
                    Response.Redirect("default.aspx");
                }

                int idToupdate = Convert.ToInt32(Request.QueryString["id"].ToString());
                ContactsDb db = new ContactsDb();
                Contact con = db.Contacts.SingleOrDefault(p => p.id == idToupdate);

                Label1.Text = con.id.ToString();
                Label2.Text = con.fname;
                Label3.Text = con.lname;

                TextBox1.Text = con.phone;
                Session["updatingContact"] = con;
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text == string.Empty ||
                TextBox2.Text == string.Empty ||
                TextBox3.Text == string.Empty)
            {
                Label1.Text = "Please enter proper details first";
                return;
            }

            Contact con = new Contact();
            con.fname = TextBox1.Text;
            con.lname = TextBox2.Text;
            con.phone = TextBox3.Text;

            ContactsDb db = new ContactsDb();
            db.Contacts.AddObject(con);
            if (db.SaveChanges() == 1)
            {
                Label1.Text = "Contact added Successfully";
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     ContactsDb db = new ContactsDb();
     Repeater1.DataSource = db.Contacts;
     Repeater1.DataBind();
 }