public static bool MailSendApplicationToParent(StudentRecord studentRecord) { try { // Create the email object first, then add the properties. var mail = SendGrid.GetInstance(); mail.From = new MailAddress("*****@*****.**", "GlobalSportAcademyGroup"); // Create credentials, specifying your user name and password. var credentials = new NetworkCredential(ClsGlobalscs.sgun, ClsGlobalscs.sgpw); // Create an SMTP transport for sending email. var transportWeb = Web.GetInstance(credentials); // mail.AddTo(ClsGlobalscs.AdminName + " <" + ClsGlobalscs.AdminEmail + ">"); //check to see who is getting the email if (studentRecord.FatherEmail == "") { mail.AddTo(studentRecord.MotherName + " <" + studentRecord.MotherEmail + ">"); } else { mail.AddTo(studentRecord.FatherName + " <" + studentRecord.FatherEmail + ">"); } //if both are present, add the cc if (studentRecord.FatherEmail != "" && studentRecord.MotherEmail != "") { mail.AddCc(studentRecord.MotherName + " <" + studentRecord.MotherEmail + ">"); } mail.Subject = "Welcome from the GlobalSportAcademyGroup"; /********************/ string body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head>"; body += "<body style=\"font-size: 11px; margin: 0px; background: #ffffff; font-family: Lucida Grande, Lucida Sans Unicode, Arial, Verdana, sans-serif; color: #333; padding: 0px;\">"; body += "<table cellspacing=\"0\" border=\"0\" cellpadding=\"10\" width=\"100%\">"; body += "<tr>"; body += "<td align=\"center\" valign=\"top\" style=\"font-size: 11px; font-family: Lucida Grande, Lucida Sans Unicode, Arial, Verdana, sans-serif; color: #333;\" bgcolor=\"#FFFFFF\">"; body += " <table cellspacing=\"0\" border=\"0\" cellpadding=\"0\" width=\"620\">"; body += " <tr>"; body += " <td align=\"left\" valign=\"top\" style=\"font-size: 11px; font-family: Lucida Grande, Lucida Sans Unicode, Arial, Verdana, sans-serif; color: #333;\" bgcolor=\"#ffffff\">"; body += " <table cellspacing=\"20\" border=\"0\" cellpadding=\"0\" width=\"620\">"; body += " <tr>"; body += " <td align=\"left\" valign=\"bottom\" style=\"font-size: 11px; font-family: Lucida Grande, Lucida Sans Unicode, Arial, Verdana, sans-serif; color: #333;\">"; body += " <a href=\"" + ClsGlobalscs.WebsiteURL + "\"><img alt=\"logo\" src=\"" + ClsGlobalscs.WebsiteURL + "/img/GSAG_Logo_620.png\" style=\"float:right;\"></a>"; body += " </td>"; body += " <td align=\"right\" valign=\"bottom\" style=\"width=\"200\"> "; //body += " <font color=\"#FFFFFF\" size=\"4\">" + DateTime.Now + "</font>"; body += " </td>"; body += " </tr>"; body += " </table>"; body += " </td>"; body += " </tr>"; body += " <tr>"; body += " <td align=\"center\" valign=\"top\" style=\"font-size: 11px; border-bottom: 1px solid #86919d;font-family: Lucida Grande, Lucida Sans Unicode, Arial, Verdana, sans-serif; border-right: 1px solid #86919d; color: #333; border-left: 1px solid #86919d;\" bgcolor=\"#FFFFFF\">"; body += " <table cellspacing=\"0\" border=\"0\" cellpadding=\"0\" width=\"618\">"; body += " <tr>"; body += " <td bgcolor=\"#edeff0\" style=\"font-size: 11px; border-bottom: 1px solid #d7d8d9; font-family: Lucida Grande, Lucida Sans Unicode, Arial, Verdana, sans-serif; color: #333;\">"; body += " <table cellspacing=\"0\" border=\"0\" cellpadding=\"0\" width=\"100%\">"; body += " <tr>"; body += " <td style=\"font-size: 11px; font-family: Lucida Grande, Lucida Sans Unicode, Arial, Verdana, sans-serif; color: #333;\">"; body += " <table cellspacing=\"0\" border=\"0\" cellpadding=\"20\" width=\"100%\">"; body += " <tr>"; body += " <td>"; body += " <strong>Hello, below are the details from your recent application. A representative will be in contact with you shortly.<br>"; body += " <br /></strong>"; body += " </td>"; body += " </tr>"; body += " </table>"; body += " </td>"; body += " </tr>"; body += " </table>"; body += " </td>"; body += " </tr>"; body += " <tr>"; body += " <td style=\"font-size: 11px; border-bottom: 1px solid #d7d8d9; font-family: Lucida Grande, Lucida Sans Unicode, Arial, Verdana, sans-serif; color: #333;\">"; body += " <table cellspacing=\"20\" border=\"0\" cellpadding=\"0\" width=\"100%\">"; body += " <tr>"; body += " <td align=\"left\" valign=\"top\" style=\"font-size: 11px; font-family: Lucida Grande, Lucida Sans Unicode, Arial, Verdana, sans-serif; color: #333;\" colspan=\"2\">"; body += " <strong>Student Name: </strong>" + studentRecord.StudentName + "<br>"; body += " <strong>Student Birthdate: </strong>" + studentRecord.Birthdate + "<br>"; body += " <strong>Student Gender: </strong>" + studentRecord.Gender + "<br>"; body += " <strong>Student Email: </strong>" + studentRecord.StudentEmail + "<br>"; body += " <strong>Student Cell: </strong>" + studentRecord.StudentCell + "<br>"; body += " <strong>Present School: </strong>" + studentRecord.PresentSchool + "<br>"; body += " <strong>Present Grade: </strong>" + studentRecord.PresentGrade + "<br>"; body += " <strong>School Of Choice: </strong>" + studentRecord.SchoolOfChoice + "<br>"; body += " <strong>Sport Of Choice: </strong>" + studentRecord.SportOfChoice + "<br>"; body += " <strong>Grade Requested: </strong>" + studentRecord.GradeRequested + "<br><br>"; body += " <strong>Fathers Name: </strong>" + studentRecord.FatherName + "<br>"; body += " <strong>Fathers Mailing Address: </strong>" + studentRecord.FatherAddress + "<br>"; body += " <strong>Fathers Cell: </strong>" + studentRecord.FatherCell + "<br>"; body += " <strong>Fathers Email: </strong>" + studentRecord.FatherEmail + "<br><br>"; body += " <strong>Mothers Name: </strong>" + studentRecord.MotherName + "<br>"; body += " <strong>Mothers Mailing Address: </strong>" + studentRecord.MotherAddress + "<br>"; body += " <strong>Mothers Cell: </strong>" + studentRecord.MotherCell + "<br>"; body += " <strong>Mothers Email: </strong>" + studentRecord.MotherEmail + "<br><br>"; //body += " The article <strong>" + articleName + "</strong> has been shared with you by your coach.<br><br>Login to your locker and view it in your blueprint!<br>"; body += " <br><br><strong> - The GlobalSportAcademyGroup Team </strong><br><br>"; body += " </td>"; body += " </tr>"; body += " </table>"; body += " </td>"; body += " </tr>"; body += " <tr>"; body += " <td>"; body += " <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"20\" bgcolor=\"#edeff0\">"; body += " <tr>"; body += " <td>"; body += " <a href=\"" + ClsGlobalscs.WebsiteURL + "\"><img alt=\"logo\" src=\"" + ClsGlobalscs.WebsiteURL + "/img/globe.png\" style=\"float:right;\"></a>"; body += " </td>"; body += " </tr>"; body += " </table>"; body += " </td>"; body += " </tr>"; body += " </table>"; body += " </td>"; body += " </tr>"; body += " </table>"; body += "</td>"; body += "</tr>"; body += "</table>"; body += "</body>"; body += "</html>"; /*********************/ mail.Html = body; string textOnly = ""; //textOnly += "You have a new article shared from Coach " + coachName + Environment.NewLine; //textOnly += "Article: " + articleName + "" + Environment.NewLine; textOnly += " - The GlobalSportAcademyGroup Team"; mail.Text = textOnly; // Send the email. transportWeb.Deliver(mail); return true; } catch (Exception ex) { Console.Write("Error: " + ex.Message.ToString()); return false; } }
/// <summary> /// Updates TeamFan Instance /// </summary> /// <param name="studentRecord">StudentRecord instance that represents a record in the StudentRecord table</param> /// <returns>The StudentID that was just inserted</returns> public static int Update(StudentRecord studentRecord) { using (var db = GetConnection()) { var parameters = new DynamicParameters(); // parameters.Add("@StudentName", dbType: DbType.String, size: 150, value: studentRecord.StudentName); parameters.Add("@Birthdate", dbType: DbType.String, size: 150, value: studentRecord.Birthdate); parameters.Add("@Gender", dbType: DbType.String, size: 50, value: studentRecord.Gender); parameters.Add("@StudentEmail", dbType: DbType.String, size: 150, value: studentRecord.StudentEmail); parameters.Add("@StudentCell", dbType: DbType.String, size: 50, value: studentRecord.StudentCell); parameters.Add("@PresentSchool", dbType: DbType.String, size: 150, value: studentRecord.PresentSchool); parameters.Add("@PresentGrade", dbType: DbType.Int32, value: studentRecord.PresentGrade); parameters.Add("@SchoolOfChoice", dbType: DbType.String, size: 150, value: studentRecord.SchoolOfChoice); parameters.Add("@SportOfChoice", dbType: DbType.String, size: 50, value: studentRecord.SportOfChoice); parameters.Add("@GradeRequested", dbType: DbType.Int32, value: studentRecord.GradeRequested); parameters.Add("@FatherName", dbType: DbType.String, size: 150, value: studentRecord.FatherName); parameters.Add("@FatherAddress", dbType: DbType.String, size: 150, value: studentRecord.FatherAddress); parameters.Add("@FatherCell", dbType: DbType.String, size: 50, value: studentRecord.FatherCell); parameters.Add("@FatherEmail", dbType: DbType.String, size: 150, value: studentRecord.FatherEmail); parameters.Add("@MotherName", dbType: DbType.String, size: 150, value: studentRecord.MotherName); parameters.Add("@MotherAddress", dbType: DbType.String, size: 150, value: studentRecord.MotherAddress); parameters.Add("@MotherCell", dbType: DbType.String, size: 50, value: studentRecord.MotherCell); parameters.Add("@MotherEmail", dbType: DbType.String, size: 150, value: studentRecord.MotherEmail); //parameters.Add("@DateSubmitted", dbType: DbType.DateTime, value: studentRecord.DateSubmitted); parameters.Add("@Contacted", dbType: DbType.Boolean, value: studentRecord.Contacted); parameters.Add("@DateContacted", dbType: DbType.DateTime, value: studentRecord.DateContacted); parameters.Add("@ContactedBy", dbType: DbType.String, size: 150, value: studentRecord.ContactedBy); //parameters.Add("@UserID", dbType: DbType.Guid, value: studentRecord.UserID); parameters.Add("@Status", dbType: DbType.Int32, value: studentRecord.Status); parameters.Add("@Type", dbType: DbType.Int32, value: studentRecord.Type); parameters.Add("@Notes", dbType: DbType.String, size: 500, value: studentRecord.Notes); parameters.Add("@StudentID", dbType: DbType.Int32, value: studentRecord.StudentID); parameters.Add("@RecordsAffected", dbType: DbType.Int32, direction: ParameterDirection.Output); db.Execute("spUpdateStudentRecord", parameters, commandType: CommandType.StoredProcedure); db.Execute("[dbo].[spUpdateStudentRecord]", parameters, commandType: CommandType.StoredProcedure); var recordsAffected = parameters.Get<int>("@RecordsAffected"); return recordsAffected; } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (txtStudentName.Text == "") { txtStudentName.Focus(); lblStudentNameError.Visible = true; return; } else { lblStudentNameError.Visible = false; } if (ddlGender.SelectedItem.ToString() == "Select") { ddlGender.Focus(); lblGenderError.Visible = true; return; } else { lblGenderError.Visible = false; } if (txtPresentSchool.Text == "") { txtPresentSchool.Focus(); lblPresentSchoolError.Visible = true; return; } else { lblPresentSchoolError.Visible = false; } if (ddlPresentGrade.SelectedItem.ToString() == "Select") { ddlPresentGrade.Focus(); lblPresentGradeError.Visible = true; return; } else { lblPresentGradeError.Visible = false; } if (ddlSchoolOfChoice.SelectedItem.ToString() == "Select") { ddlSchoolOfChoice.Focus(); lblSchoolOfChoiceError.Visible = true; return; } else { lblSchoolOfChoiceError.Visible = false; } if (ddlSportOfChoiceOkotoks.SelectedItem.ToString() == "Select" && ddlSportOfChoiceSpringbank.SelectedItem.ToString() == "Select") { ddlSportOfChoiceOkotoks.Focus(); lblSportOfChoiceError.Visible = true; return; } else { lblSportOfChoiceError.Visible = false; } if (ddlGradeRequested.SelectedItem.ToString() == "Select") { ddlGradeRequested.Focus(); lblGradeRequestedError.Visible = true; return; } else { lblGradeRequestedError.Visible = false; } if (txtFatherEmail.Text == "" && txtMotherEmail.Text == "") { txtFatherEmail.Focus(); lblParentEmailError.Visible = true; return; } else { lblParentEmailError.Visible = false; } StudentRecord studentRecord; var sportOfChoice = ""; if (ddlSchoolOfChoice.SelectedIndex == 1) { sportOfChoice = ddlSportOfChoiceOkotoks.SelectedItem.ToString(); } else { sportOfChoice = ddlSportOfChoiceSpringbank.SelectedItem.ToString(); } studentRecord = new StudentRecord { StudentName = txtStudentName.Text, Birthdate = txtBirthdate.Text, Gender = ddlGender.SelectedItem.ToString(), StudentEmail = txtStudentEmail.Text, StudentCell = txtStudentCell.Text, PresentSchool = txtPresentSchool.Text, PresentGrade = Convert.ToInt32(ddlPresentGrade.SelectedItem.ToString()), SchoolOfChoice = ddlSchoolOfChoice.SelectedItem.ToString(), SportOfChoice = sportOfChoice, GradeRequested = Convert.ToInt32(ddlGradeRequested.SelectedItem.ToString()), FatherName = txtFatherName.Text, FatherAddress = txtFatherAddress.Text, FatherCell = txtFatherCell.Text, FatherEmail = txtFatherEmail.Text, MotherName = txtMotherName.Text, MotherAddress = txtMotherAddress.Text, MotherCell = txtMotherCell.Text, MotherEmail = txtMotherEmail.Text, Contacted = false, DateContacted = DateTime.Now, DateSubmitted = DateTime.Now, ContactedBy ="", Status = 0, Type = 0, Notes = "", UserID = Guid.NewGuid() }; //insert the record var intRes = StudentRecordDAO.Insert(studentRecord); if (intRes > 0) { bool res = ClsUtilities.MailSendApplicationToParent(studentRecord); bool res2 = ClsUtilities.MailSendApplicationToAdmin(studentRecord); Response.Redirect("success.aspx"); } }