Example #1
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Establishment tempE = EstablishmentDB.getTempEstablishmentByEmail(email.Text);

        if (ddlStatus.SelectedValue == "pending")
        {
            lblOutput.Text = "The status cannot be pending! Please choose approve or dismiss.";
            return;
        }

        else
        {
            tempE.Status = ddlStatus.SelectedValue;
            int num = EstablishmentDB.updatetempStatus(tempE);
            if (num != 1)
            {
                lblOutput.Text = "Cannot Update Status!";
            }
            else
            {
                lblOutput.Text = "";
                Panel1.Visible = false;
                SmtpClient client = new SmtpClient("smtp.gmail.com");
                client.EnableSsl   = true;
                client.Credentials = new NetworkCredential("*****@*****.**", "inft.3050");
                MailMessage msg = new MailMessage("*****@*****.**", tempE.Email);
                if (ddlStatus.SelectedValue == "approved")
                {
                    Admins        a      = AdminDB.getAdminbyEmail(Session["email"].ToString());
                    Establishment est    = new Establishment(tempE.Email, tempE.Name, tempE.Password, tempE.Type, tempE.Phone, tempE.Address, tempE.ID, a);
                    int           number = EstablishmentDB.insertEstablishment(est);
                    if (number != 1)
                    {
                        Label2.Text = "Cannot Register to Establishment table!";
                        return;
                    }
                    else
                    {//sending email to establishment when accept
                        msg.Subject = "Life++ Application!";
                        msg.Body    = "Your request for joining Life++ have been approved. You are now part of our system and can start using now.\n\n Thank you for joining our system. \n\n Team Life++";
                        client.Send(msg);
                        Label2.Text = "Information successfully Updated! Approval email sent to " + email.Text + " .";
                    }
                }
                else
                {//sending email to establishment when dismissed
                    msg.Subject = "Life++ Application!";
                    msg.Body    = "Your request for joining Life++ have been dismissed. Thank you for interesting to join our system.\n\n For more information, please contact us at [email protected] \n\n Team Life++ ";
                    client.Send(msg);
                    Label2.Text = "Information successfully Updated! Dismissed email sent to " + email.Text + " .";
                }
                Panel1.Visible = false;
                List <Establishment> tempestlists = EstablishmentDB.getAllTempEstablishmentsbyStatus("pending");
                gvpending.DataSource = tempestlists;
                gvpending.DataBind();
                if (tempestlists.Count == 0)
                {
                    lblSelectError.Text = "There are no pending request left right now.";
                }
                else
                {
                    lblSelectError.Text = "There are " + tempestlists.Count + " records found";
                }
            }
        }
    }