Ejemplo n.º 1
0
    //Submit the enquiry / contact info to admin
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string name, mobile, msg, subject;

            mobile  = txtEmail.Text.Trim();
            name    = txtFirstName.Text.Trim() + " " + txtLastName.Text.Trim();
            subject = txtSubject.Text.Trim();
            msg     = txtMessage.Text.Trim();

            if (name == "")
            {
                lblmsg.Text = "Please enter your name";
            }

            else if (mobile == "")
            {
                lblmsg.Text = "Please enter your mobile number";
            }

            else if (subject == "")
            {
                lblmsg.Text = "Please enter your subject";
            }
            else
            {
                ContactInfo data = new ContactInfo(); //add data to class
                data.Mobile = mobile;

                data.Msg     = msg;
                data.Name    = name;
                data.Subject = subject;

                int ans = new ContactInfoAction().AddContactInfo(data); //method calling to add enquiry
                if (ans > 0)
                {
                    txtEmail.Text     = "";
                    txtFirstName.Text = "";
                    txtLastName.Text  = "";
                    txtSubject.Text   = "";
                    txtMessage.Text   = "";;
                    lblmsg.Text       = "Thank you for contacting us. We will be right back to you shortly.";
                }
            }
        }
        catch (Exception ex)
        {
            lblmsg.Text = ex.Message;
        }
    }
Ejemplo n.º 2
0
    //Delete Enquiry implementation
    protected void rptrEnquiry_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            NZEduEntities n = new NZEduEntities();

            if (e.CommandName.Equals("del")) // delete one enquiry
            {
                int     NewsID = int.Parse(e.CommandArgument.ToString());
                Contact data   = new ContactInfoAction().ViewEnquiry(NewsID); // getting a News to delete
                if (data != null)
                {
                    n.Contacts.Attach(data);
                    n.Contacts.Remove(data);
                    n.SaveChanges();
                    BindEnquiry();
                    lblmsg.Text = "*Enquiry Deleted!";
                }
            }
            if (e.CommandName.Equals("delall"))              // delete all enquiries
            {
                var ctid = from b in n.Contacts select b.id; // Get all enquiry Id(s)
                foreach (var nid in ctid)
                {
                    Contact bt = new Contact();
                    bt = n.Contacts.Single(c => c.id == nid); // lamda expression
                    n.Contacts.Attach(bt);
                    n.Contacts.Remove(bt);
                }
                n.SaveChanges();

                BindEnquiry(); // method calling
            }
        }
        catch (Exception ex)
        {
            lblmsg.Text = ex.Message;
        }
    }