Пример #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                ResetMsgs();

                //validate fields and save record
                if (IsValidInput(txtFirstName.Text) && IsValidInput(txtLastName.Text) && IsValidInput(txtPhoneNo.Text))
                {

                    ContactsDataContext db = new ContactsDataContext();

                    Contact addContact = new Contact();

                    addContact.FirstName = txtFirstName.Text;
                    addContact.LastName = txtLastName.Text;
                    addContact.PhoneNo = txtPhoneNo.Text;

                    db.Contacts.InsertOnSubmit(addContact);
                    db.SubmitChanges();

                    ClearForm();
                    pnlSuccess.Visible = true;
                    ltlSuccess.Text = "Contact " + txtFirstName.Text.ToString() + " " + txtLastName.Text.ToString() + " saved";

                }
                else
                {
                    //validation of text fields
                    if (!(IsValidInput(txtFirstName.Text)))
                    {
                        divFirstName.Attributes["class"] = "clearfix error";
                        txtFirstName.CssClass = "error";
                        helpFirstName.Visible = true;
                    }
                    if (!(IsValidInput(txtLastName.Text)))
                    {
                        divLastName.Attributes["class"] = "clearfix error";
                        txtLastName.CssClass = "error";
                        helpLastName.Visible = true;
                    }
                    if (!(IsValidInput(txtPhoneNo.Text)))
                    {
                        divPhoneNo.Attributes["class"] = "clearfix error";
                        txtPhoneNo.CssClass = "error";
                        helpPhoneNo.Visible = true;
                    }
                    pnlError.Visible = true;
                    ltlError.Text = "Please correct the errors below";

                }
            }
            catch (Exception ex)
            {
                pnlError.Visible = true;
                ltlError.Text = ex.Message;
            }
        }
Пример #2
0
 public void AddContact(User objUser, Contact objContact) {
    User tempUser = _Container.Users.FirstOrDefault(user => user.Id == objUser.Id);
    tempUser.Contacts.Add(objContact);
    _Container.SaveChanges();
 }
 partial void UpdateContact(Contact instance);
 partial void DeleteContact(Contact instance);
 partial void InsertContact(Contact instance);