public static MailContent createUserReportEmail(UserPurchase user, QuestionnaireReport report)
 {
     MailContent mailContent = new MailContent();
     mailContent.MailFrom = adminEmail;
     mailContent.MailingAdress = user.Email;
     mailContent.Subject = "FSMA Self Assessment Report for " + user.FacilityName;
     return mailContent;
 }
 public QuestionnaireReportForUser(QuestionnaireReport report, UserPurchase user)
 {
     this.Report       = report;
     this.UserPurchase = user;
 }
        public HttpResponseBase ExportStatistics()
        {
            ExcelWriter writer = new ExcelWriter();

            writer.startWorksheet("Users");
            writer.startRow();
            writer.addCell("Name");
            writer.addCell("Email");
            writer.addCell("Facility");
            writer.addCell("Size of Facility");
            writer.addCell("Industrial Classification");
            writer.addCell("2nd Classification");
            writer.addCell("3rd Classification");
            writer.addCell("Registration Date");
            writer.addCell("Expiration Date");
            writer.addCell("Overall H,M,Low");
            writer.addCell("Overall Score #");

            //Header
            int questionId = 1;
            IList <Category> categories = _context.Categories.ToList();

            foreach (Category category in categories)
            {
                writer.addCell(category.Index + ". " + category.Title + "  H,M,L");
                writer.addCell(category.Index + ". " + category.Title + "  Score");
                writer.addCell(category.Index + ". " + category.Title + "  Max");
                writer.addCell(category.Index + ". " + category.Title + "  Score #");
                for (int i = 0; i < category.Questions.Count; i++)
                {
                    writer.addCell("Q." + questionId + " answer");
                    writer.addCell("Answer Score");
                    writer.addCell("Max Score");
                    questionId++;
                }
            }
            writer.endRow();

            //Cycle through user entries and create lists
            IList <UserEntry> ul = (new UsersList()).Users;

            foreach (UserEntry userEntry in ul)
            {
                if (!userEntry.WasCompleteQuestionnaire)
                {
                    continue;
                }

                writer.startRow();

                //Common info
                writer.addCell(userEntry.User.Name);
                writer.addCell(userEntry.User.Email);
                writer.addCell(userEntry.User.FacilityName);
                writer.addCell(userEntry.User.SizeOfFacilityValue);
                writer.addCell(userEntry.User.IndustrialClassificationValue);
                writer.addCell(userEntry.User.AdditionalProductClassificationValue);
                writer.addCell(userEntry.User.AnotherProductClassificationValue);
                writer.addCell(userEntry.User.UserRegistrationDate);
                writer.addCell(userEntry.User.UserExpirationDate);

                //Get report for this user
                QuestionnairePrototype.Models.Report.QuestionnaireReport report = _questionnaireAnswersRepository.getQuestionnaireReport(userEntry.User.Id);

                //Overall
                writer.addCell(report.Overall.RiskTypeName);
                writer.addCell(report.Overall.OverallScore);

                //Categories and answers
                foreach (CategoryRecomendation category in report.Categories)
                {
                    writer.addCell(category.RiskTypeName);
                    writer.addCell(category.QuestionsValueSum);
                    writer.addCell(category.QuestionsMaxValueSum);
                    writer.addCell(category.CategoryScore);
                    foreach (QuestionRecomendation question in category.QuestionRecomendations)
                    {
                        writer.addCell(question.answerId);
                        writer.addCell(question.checkedValue);
                        writer.addCell(question.maxValue);
                    }
                }
                writer.endRow();
            }

            writer.endWorksheet();
            writer.endWorkbook();

            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=Users submissions.xls");
            Response.Charset     = "";
            Response.ContentType = "application/ms-excel";
            Response.Write(writer.getString());
            Response.End();

            return(Response);
        }
 public QuestionnaireReportForUser(QuestionnaireReport report, UserPurchase user)
 {
     this.Report = report;
     this.UserPurchase = user;
 }
 public UserDetails(UserPurchase user, QuestionnaireReport questionnaireReport)
 {
     this.UserPurchase = user;
     this.QuestionnaireReport = questionnaireReport;
 }
        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");
            //}
        }