Пример #1
0
        private void SaveEmail(string email, string fname, string lname, string zip, string ipAddress)
        {
            lock (SyncRoot)
            {
                string path = Server.MapPath(@"/App_Data/QuickJoins.txt");

                bool existed = System.IO.File.Exists(path);
                using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.UTF8))
                {
                    if (!existed)
                    {
                        sw.WriteLine("Email\tFName\tLName\tZip\tIP\tDate");
                    }
                    if (!Utils.IsValidName(fname))
                        fname = null;

                    if (!Utils.IsValidName(lname))
                        lname = null;

                    if (!Utils.IsValidEmail(email))
                        return;
                    if (!Utils.IsValidZip(zip))
                        return;

                    int ipCount = 0;
                    if (_IPCount.TryGetValue(ipAddress, out ipCount) && ipCount > _MaxEntriesPerIP)
                        return;

                    _IPCount[ipAddress] = ipCount + 1;

                    string el = email.ToLower().Trim();
                    if (_SeenEmails.ContainsKey(el))
                        return;

                    //send email notice
                    MailHandler thisMailer = new MailHandler();

                    Registrant registrant = new Registrant();

                    registrant.Email = email;
                    registrant.FirstName = fname;
                    registrant.LastName = lname;
                    registrant.ZipCode = zip;

                    thisMailer.SendContactEmail(registrant, "JOIN");

                    sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", email, fname, lname, zip, ipAddress, DateTime.Now.ToString("r"));
                    _SeenEmails[el] = el;
                    sw.Flush();

                }
            }
        }
        public ActionResult Index(Registrant registrant)
        {
            if (ModelState.IsValid)
            {
                db.Registrants.AddObject(registrant);
                db.SaveChanges();

                MailHandler thisMailer = new MailHandler();
                thisMailer.SendContactEmail(registrant);

                return RedirectToAction("ThankYou");

            }

            return View(registrant);
        }