Example #1
0
        internal static void sendEmailToUser(string email, Product.ProudctType productType)
        {
            var emailServer = getSMTPServer();
            IMailService mailService = new SmptMailService(emailServer);

            MailContent mail = new MailContent();
            mail.MailingAdress = email;
            mail.MailFrom = getFromAddress();
            mail.ReplyToAddress = getReplyToAddress();

            //AFFI English
            if(productType == Product.ProudctType.AffiEnglish)
            {
                mail.Subject = getAFFIEmailSubject();
                mail.HtmlText = getEmailBodyForUserAFFISite();
            }
            //AFFI Spanish
            else
            {
                mail.Subject = getAFFISpanishEmailSubject();
                mail.HtmlText = getEmailBodyForUserAFFISpanishSite();
            }

            mailService.sendMail(mail, true);
        }
Example #2
0
        internal static void sendErrorEmail(string message)
        {
            var emailServer = getSMTPServer();
            IMailService mailService = new SmptMailService(emailServer);

            var emailRecipient = System.Configuration.ConfigurationManager.AppSettings["errorEmailRecipient"];

            MailContent mail = new MailContent();
            mail.MailingAdress = emailRecipient;
            mail.MailFrom = getFromAddress();
            mail.Subject = "AFFI Signup Error";
            mail.HtmlText = message;
            mailService.sendMail(mail, true);
        }
Example #3
0
        internal static void sendEmailToAffi(Product.ProudctType productType)
        {
            var emailServer = getSMTPServer();
            IMailService mailService = new SmptMailService(emailServer);

            MailContent mail = new MailContent();
            mail.MailingAdress = getAFFIToAddress();
            mail.MailFrom = getFromAddress();
            mail.ReplyToAddress = getReplyToAddress();
            //AFFI English
            //if (productType == Product.ProudctType.AffiEnglish)
            //{
                mail.Subject = getAFFIEmailSubject();
                mail.HtmlText = getEmaiBodyforAffi();
            //}
            //AFFI Spanish
            //else
            //{
            //    mail.Subject = getAFFISpanishEmailSubject();
            //    mail.HtmlText = getEmaiBodyforAffiSpanish();
            //}

            mailService.sendMail(mail, true);
        }
        public ActionResult Activate(PurchasedItemModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
                return Redirect("Index");

            string facilityName = model.Facility;
            string userName = model.Name;
            string email = model.Email;
            string dateOfPurchase = model.DateOfPurchase;
            List<PurchasedItem> purchasedItems = GetStoredPurchasedItems();
            if (purchasedItems == null)
            {
                return LogOutAndRedirectToLoginPage();
            }
            DateTime date = DateTime.Parse(dateOfPurchase);

            var purchasedItem = purchasedItems.Find(i => Math.Abs(i.DateOfPurchase.Subtract(date).TotalSeconds) < 1);

            if (purchasedItem != null)
            {
                var count = context.UserPurchases.Where(u => EntityFunctions.DiffSeconds(u.DateOfPurchase, purchasedItem.DateOfPurchase) < 1).Count();

                //if(count != 0)
                //    return Content("<html><head></head><body><h1>Error! This item already activated </h1></body></html>");

                var salt = GenerateSequenceOfChars(20);
                // TODO: check facility name length
                var password = GeneratePassword(facilityName);

                //TODO: move following code to method
                var userPurchase = new UserPurchase();

                userPurchase.Email = email;
                userPurchase.ActivatorsEmail = User.Identity.Name;
                userPurchase.Name = userName;
                userPurchase.PasswordSalt = salt;
                userPurchase.Password = HashPassword(password, salt);
                userPurchase.FacilityName = facilityName;
                userPurchase.DateOfPurchase = purchasedItem.DateOfPurchase;
                userPurchase.UserRegistrationDate = DateTime.Now;
                userPurchase.UserExpirationDate = DateTime.Now.AddMonths(6);

                context.UserPurchases.Add(userPurchase);
                context.SaveChanges();

                HttpContext.Session["lastPurchase"] = userPurchase;
                HttpContext.Session["lastPurchasePassword"] = password;

                //Send an email to user
                IMailService mailService = new SmptMailService(System.Configuration.ConfigurationManager.AppSettings["smtpServer"]);

                MailContent mailContent = new MailContent();
                mailContent.MailFrom = "*****@*****.**";
                mailContent.MailingAdress = userPurchase.Email;
                mailContent.Subject = "AFFI FSMA Self-Assessment Login Credentials and Instructions";

                mailContent.HtmlText = "<html><head></head><body>Dear " + userPurchase.Name + ":<br/>" +
                "<p>When you want to begin your FSMA Self-Assessment for your facility (<b>" + userPurchase.FacilityName + "</b>), you can just click on the Login link below.</p>" +
                "<p>Your login credentials for the FSMA Self-Assessment are: </p>" +
                "<p><b>Userid: </b>" + userPurchase.Email + "</p>" +
                "<p><b>Password: </b>" + password + "</p>" +
                "<p>If you have any questions regarding the FSMA Self-Assessment Tool, please contact AFFI Vice President of Regulatory and Technical Affairs Dr. Donna Garren at <a href=\"mailto:[email protected]\">[email protected]</a> or (703) 821-0770.</p>" +
                "<p>Thank you.</p>" +
                "<p><a href=\"http://affi-fsma.seneca.com/signIn\" target=\"_blank\">Click Here to Login</a></p></body></html>";

                mailContent.PlainText = mailContent.HtmlText;
                mailService.sendMail(mailContent);

                //And if needed - to a person who had activated the purchase (if not same person)
                if (userPurchase.Email != userPurchase.ActivatorsEmail)
                {
                    mailContent.MailingAdress = userPurchase.ActivatorsEmail;
                    mailService.sendMail(mailContent);
                }

                return Redirect("Index");
            }
            else
            {
                return Content("<html><head></head><body><h1>Error!Can't find purchasedItem</h1></body></html>");
            }
        }
        public ActionResult Index(FormCollection formCollection)
        {
            //TODO: Add generation of report from existing answers in database

            //try
            //{
            QuestionnaireFormCollectionParser parser = new QuestionnaireFormCollectionParser(formCollection);
            var userId = _userRepository.GetUserByEmail(User.Identity.Name, (string)HttpContext.Session["facilityDateHash"]).Id;

            _questionnaireRepository.rewriteUserAnswersWithNew(
                userId,
                parser.QuestionAnswerMapping
            );

            UserPurchase user = _userRepository.GetUserById(userId);
            DemographicData demographicData = parser.DemographicData;

            user.SizeOfFacility = demographicData.SizeOfFacility;
            user.IndustrialClassification = demographicData.IndustrialClassification;
            user.AnotherProductClassification = demographicData.AnotherProductClassification;
            user.AdditionalProductClassification = demographicData.AdditionalProductClassification;

            _userRepository.SaveChanges();

            if (formCollection["completeLaterOnSubmit"] == "false")
            {
                _questionnaireRepository.rememberThatUserHasCompleteQuestionnaire(userId);

                QuestionnaireReport newReport = new QuestionnaireReport(parser.QuestionAnswerMapping);
                newReport.calculateScore();

                QuestionnaireReportForUser questionnaireReportForUser = new QuestionnaireReportForUser(newReport, user);

                //IMailService mailService = new MailRuMailService("senecatest", "test1234");
                IMailService mailService = new SmptMailService(System.Configuration.ConfigurationManager.AppSettings["smtpServer"]);

                String htmlText = ToHtml(
                    "MailTemplate",
                    new ViewDataDictionary(questionnaireReportForUser),
                    this.ControllerContext
                );

                MailContent userMailContent = MailConfigurator.createUserReportEmail(user, newReport);
                userMailContent.HtmlText = htmlText;
                mailService.sendMail(userMailContent);

                if (user.Email != user.ActivatorsEmail)
                {
                    //Also send an email to a person, who activated our purchase
                    MailContent activatorMailContent = MailConfigurator.createActivatorReportEmail(user, newReport);
                    activatorMailContent.HtmlText = htmlText;
                    mailService.sendMail(activatorMailContent);
                }

                MailContent managerMailContent = MailConfigurator.createManagerReportEmail(user, newReport);
                managerMailContent.HtmlText = htmlText;
                mailService.sendMail(managerMailContent);

                return View(questionnaireReportForUser);
            }
            // TODO: make special view for this message
            else
            {
                AFFIHeaderModel savedPageModel = new AFFIHeaderModel(user.FacilityName, user.Name, user.Email, true, DateTime.Now.Date);
                return View("ReportSaved", savedPageModel);
            }
            //}
            //catch
            //{
            //    return Redirect("Error");
            //}
        }