private void UpdateList()
        {
            contacts = SQLUtils.GetAllContacts();
            string literalContacts = "";

            foreach (var contact in contacts)
            {
                literalContacts += "<tr>";
                literalContacts += $"<td>{contact.FirstName}</td>";
                literalContacts += $"<td>{contact.LastName}</td>";
                literalContacts += $"<td>{contact.SSN}</td>";
                literalContacts += $"<td>";
                literalContacts += $"  <a href='HandleContact.aspx?action=update&id={contact.ContactID}'>Update</a> - ";
                literalContacts += $"  <a href='HandleContact.aspx?action=delete&id={contact.ContactID}'>Delete</a>";
                literalContacts += $"</td>";
                literalContacts += "</tr>";
            }

            ContactLiteral.Text = literalContacts;
        }
Exemple #2
0
        protected void BtnAction_Click(object sender, EventArgs e)
        {
            if (Request["action"] != null)
            {
                if (Request["id"] != null)
                {
                    if (Request["action"] == "delete")
                    {
                        SQLUtils.RemoveContact(GetID());

                        Server.Transfer("Index.aspx");
                    }
                    else if (Request["action"] == "update")
                    {
                        List <Contact> contacts = SQLUtils.GetAllContacts();
                        int            id       = GetID();

                        SQLUtils.spUpdateContact(
                            id,
                            TxtBoxFirstName.Text,
                            TxtBoxLastName.Text,
                            TxtBoxSSN.Text);

                        Server.Transfer("Index.aspx");
                    }
                }
                else if (Request["action"] == "create" && IsValid)
                {
                    SQLUtils.spAddContact(
                        TxtBoxFirstName.Text,
                        TxtBoxLastName.Text,
                        TxtBoxSSN.Text);

                    Server.Transfer("Index.aspx");
                }
            }
        }