Ejemplo n.º 1
0
        public async Task<ActionResult> AskQuestionCertificate(FormCollection fc)
        {
            if (fc["Comment2"].Contains("www.") || fc["Comment2"].Contains("http://"))
            {
                ViewBag.Success = false;

                ViewBag.ErrorMessage = "Error submitting your request!";

                return RedirectToRoute("ThankYou");
            }

            Int64 phoneNumber = 0;

            Int64.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]));

            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 = phoneNumber,
                        Location = campus,
                        Program = program,
                        HearAbout = mediaGroup + " - " + 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("*****@*****.**", "NHOntario.CA");

                            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.Bcc.Add(new MailAddress("*****@*****.**"));
                            message.Bcc.Add(new MailAddress("*****@*****.**"));

                            message.Subject = "New Lead - NHC - Certificate Question";

                            fc["CampusID"] = campus ?? fc["CampusID"];
                            fc["ProgramID"] = program ?? fc["ProgramID"];
                            fc["MediaGroupID"] = mediaGroup ?? fc["MediaGroupID"];
                            fc["MediaGID"] = 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 - 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 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");
            }
        }
Ejemplo n.º 2
0
        public bool PostData(FormCollection fc, string emailSubject = "New Lead - External")
        {
            if (fc["Comment2"].Contains("www.") || fc["Comment2"].Contains("http://"))
            {
                ViewBag.Success = false;

                ViewBag.ErrorMessage = "Error submitting your request!";

                return false;
            }

            Int64 phoneNumber = 0;

            Int64.TryParse(Helpers.Helpers.GetNumbers(fc["Telephone"]), out phoneNumber);

            if (phoneNumber == 0)
            {
                ViewBag.Success = false;

                ViewBag.ErrorMessage = "Error submitting your request! Invalid Phone Number!";

                return false;
            }

            var formData = new FormUrlEncodedContent(fc.AllKeys.ToDictionary(k => k, v => fc[v]));

            LeadsType leadsType = LeadsType.Leads;

            using (var client = new HttpClient())
            {
                var response = client.PostAsync("http://www1.campuslogin.com/Contacts/Web/ImportContactData.aspx", formData).Result;

                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 = phoneNumber,
                        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("*****@*****.**"));
                            message.Bcc.Add(new MailAddress("*****@*****.**"));

                            message.Subject = emailSubject;

                            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();

                        return false;
                    }
                }
                else
                {
                    ViewBag.Success = false;

                    ViewBag.ErrorMessage = "There was an error with your request. Please try again.";

                    return false;
                }
            }

            return true;
        }