示例#1
0
 public ActionResult Contact()
 {
     PopulateDropDownList();
     var model = new Contact();
     //set bool tutorial to false
     //forces div not to show
     model.Tutorial = false;
     return View(model);
 }
示例#2
0
 public ActionResult Contact(Contact c)
 {
     if (c.Tutorial == false)
     {
         //cancel out error
         ModelState.Remove("TutorialID");
     }
     if (ModelState.IsValid)
     {
         StringBuilder sb = new StringBuilder();
         MailMessage msg = new MailMessage();
         SmtpClient smtp = new SmtpClient();
         MailAddress address = new MailAddress("*****@*****.**");
         MailAddress from = new MailAddress(c.Email.ToString());
         msg.Subject = "Contact Me";
         msg.To.Add(address);
         msg.From = from;
         smtp.Host = "mail.ryanbutler.org";
         smtp.Port = 25;
         msg.IsBodyHtml = false;
         sb.Append(Environment.NewLine);
         sb.Append("First name: " + c.FirstName);
         sb.Append(Environment.NewLine);
         sb.Append("Last name: " + c.LastName);
         sb.Append(Environment.NewLine);
         sb.Append("Email: " + c.Email);
         if (c.Tutorial == true)
         {
             sb.Append(Environment.NewLine);
             TutorialQuestionYes(sb, c);
         }
         else
         {
             sb.Append(Environment.NewLine);
             TutorialQuestionNo(sb);
         }
         sb.Append("Comments: " + c.Comment);
         msg.Body = sb.ToString();
         try
         {
             smtp.Send(msg);
             smtp.Dispose();
             msg.Dispose();
             return View("Message");
         }
         catch (Exception)
         {
             return View("Error");
         }
     }
     var model = new Contact();
     //send the bool tutorial radio button from the model to the view
     //in order to keep the div open
     model.Tutorial = c.Tutorial;
     PopulateDropDownList(c.TutorialID);
     return View(model);
 }
示例#3
0
 private string TutorialQuestionYes(StringBuilder sb, Contact c)
 {
     sb.Append("Tutorial question? " + "Yes");
     string selectedItem = GetTutorialNameFromSelectedValue(c.TutorialID);
     sb.Append(Environment.NewLine);
     sb.Append("Which tutorial? " + selectedItem.ToString());
     sb.Append(Environment.NewLine);
     return sb.ToString();
 }