public async Task <ActionResult> ContactMedixOnlineForm(FormCollection fc) { var formData = new FormUrlEncodedContent(fc.AllKeys.ToDictionary(k => k, v => fc[v])); using (var client = new HttpClient()) { var response = await client.PostAsync("http://www1.campuslogin.com/Contacts/Web/ImportContactData.aspx", formData); if (response.IsSuccessStatusCode) { ViewBag.Success = true; var campus = campuses.FirstOrDefault(x => x.Key == Convert.ToInt32(fc["CampusID"])).Value; var program = programs.FirstOrDefault(x => x.Key == Convert.ToInt32(fc["ProgramID"])).Value; var mediaSource = mediaSources.FirstOrDefault(x => x.Key == Convert.ToInt32(fc["MediaGroupID"])).Value; var lead = new LeadsDTO { Date = DateTime.Now, FirstName = fc["FirstName"], LastName = fc["LastName"], Email = fc["Email"], Telephone = fc["Telephone"] != null?Convert.ToInt64(fc["Telephone"]) : 0, Location = campus, Program = program, HearAbout = mediaSource, Comments = fc["Comment2"] }; var leads = new Leads(); leads.Insert(lead); try { using (var mailClient = new SmtpClient("smtp.gmail.com")) { mailClient.Credentials = new NetworkCredential("ccgactiveleads", "Medixcollege1"); mailClient.Port = 587; var message = new MailMessage(); message.From = new MailAddress("*****@*****.**", "MedixCollege.net"); message.To.Add(new MailAddress("*****@*****.**")); if (fc["CampusID"].ToString() == "246") { message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); } if (fc["CampusID"].ToString() == "243") { message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); } if (fc["CampusID"].ToString() == "242") { message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); } if (fc["CampusID"].ToString() == "244") { message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); } if (fc["CampusID"].ToString() == "241") { message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); } if (fc["CampusID"].ToString() == "240") { message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); } message.Subject = "New Lead - Medix Online - Contact Medix Online"; fc["CampusID"] = campus ?? fc["CampusID"]; fc["ProgramID"] = program ?? fc["ProgramID"]; fc["MediaGroupID"] = mediaSource ?? fc["MediaGroupID"]; var stringArray = (from key in fc.AllKeys from value in fc.GetValues(key) where key != "ORGID" && key != "MailListID" select string.Format("{0}: {1}" + Environment.NewLine, HttpUtility.UrlEncode(key), value)).ToArray(); var body = "New Lead - Medix" + Environment.NewLine + Environment.NewLine; var data = string.Join(",", stringArray).Replace(",", ""); data = data.Replace("CampusID", "Location"); data = data.Replace("FirstName", "First Name"); data = data.Replace("Lastname", "Last Name"); data = data.Replace("MediaGroupID", "Media Source"); data = data.Replace("ProgramID", "Program"); data = data.Replace("Comment2", "Comments"); message.Body = body + data; message.IsBodyHtml = false; mailClient.EnableSsl = true; mailClient.Send(message); } } catch (Exception ex) { ViewBag.Success = false; ViewBag.ErrorMessage = ex.Message.ToString(); } } else { ViewBag.Success = false; ViewBag.ErrorMessage = "There was an error with your request. Please try again."; } return(View("ThankYou")); } }
public async Task <ActionResult> ExternalPost(FormCollection fc) { if (fc["Comment2"].Contains("www.") || fc["Comment2"].Contains("http://")) { ViewBag.Success = false; ViewBag.ErrorMessage = "Error submitting your request!"; return(RedirectToRoute("ThankYou")); } double phoneNumber = 0; double.TryParse(Helpers.Helpers.GetNumbers(fc["Telephone"]), out phoneNumber); if (phoneNumber == 0) { ViewBag.Success = false; ViewBag.ErrorMessage = "Error submitting your request! Invalid Phone Number!"; return(RedirectToRoute("ThankYou")); } var formData = new FormUrlEncodedContent(fc.AllKeys.ToDictionary(k => k, v => fc[v])); LeadsType leadsType = LeadsType.Leads; using (var client = new HttpClient()) { var response = await client.PostAsync("http://www1.campuslogin.com/Contacts/Web/ImportContactData.aspx", formData); if (response.IsSuccessStatusCode) { ViewBag.Success = true; var campus = campuses.FirstOrDefault(x => x.Key == Convert.ToInt32(fc["CampusID"])).Value; var program = programs.FirstOrDefault(x => x.Key == Convert.ToInt32(fc["ProgramID"])).Value; var mediaGroup = mediaGroups.FirstOrDefault(x => x.Key == Convert.ToInt32(fc["MediaGroupID"])).Value; var mediaSource = mediaSources.FirstOrDefault(x => x.Key == Convert.ToInt32(fc["MediaID"])).Value; var lead = new LeadsDTO { Date = DateTime.Now, FirstName = fc["FirstName"], LastName = fc["LastName"], Email = fc["Email"], Telephone = fc["Telephone"] != null?Convert.ToInt64(fc["Telephone"]) : 0, Location = campus, Program = program, HearAbout = mediaSource, Comments = fc["Comment2"] }; if (campus == "Baltimore") { leadsType = LeadsType.LeadsBaltimore; } else { leadsType = LeadsType.LeadsNewCastle; } var leads = new Leads(leadsType); leads.Insert(lead); try { using (var mailClient = new SmtpClient("smtp.gmail.com")) { mailClient.Credentials = new NetworkCredential("ccgactiveleads", "Medixcollege1"); mailClient.Port = 587; var message = new MailMessage(); message.From = new MailAddress("*****@*****.**", "MedixCollege.net"); message.To.Add(new MailAddress("*****@*****.**")); //if (fc["CampusID"].ToString() == "246") //{ // message.To.Add(new MailAddress("*****@*****.**")); //} message.Bcc.Add(new MailAddress("*****@*****.**")); if (leadsType == LeadsType.LeadsBaltimore) { message.Bcc.Add(new MailAddress("*****@*****.**")); } else if (leadsType == LeadsType.LeadsNewCastle) { message.Bcc.Add(new MailAddress("*****@*****.**")); } message.Subject = "New Lead - External"; fc["CampusID"] = campus ?? fc["CampusID"]; fc["ProgramID"] = program ?? fc["ProgramID"]; fc["MediaGroupID"] = mediaGroup ?? fc["MedaGroupID"]; fc["MediaID"] = mediaSource ?? fc["MediaID"]; var stringArray = (from key in fc.AllKeys from value in fc.GetValues(key) where key != "ORGID" && key != "MailListID" select string.Format("{0}: {1}" + Environment.NewLine, HttpUtility.UrlEncode(key), value)).ToArray(); var body = "New Lead - External" + Environment.NewLine + Environment.NewLine; var data = string.Join(",", stringArray).Replace(",", ""); data = data.Replace("CampusID", "Location"); data = data.Replace("FirstName", "First Name"); data = data.Replace("Lastname", "Last Name"); data = data.Replace("MediaGroupID", "Media Group"); data = data.Replace("MediaID", "Media"); data = data.Replace("ProgramID", "Program"); data = data.Replace("Comment2", "Comments"); message.Body = body + data; message.IsBodyHtml = false; mailClient.EnableSsl = true; mailClient.Send(message); } } catch (Exception ex) { ViewBag.Success = false; ViewBag.ErrorMessage = ex.Message.ToString(); } } else { ViewBag.Success = false; ViewBag.ErrorMessage = "There was an error with your request. Please try again."; } } return(View("ThankYou")); }