Exemplo n.º 1
0
 public ActionResult GetReportClient(string reportId)
 {
     var report = _emailReportService.GetReportById(reportId);
     if (report.Email == null)
         throw new Exception("Email has not been received yet.");
     var model = new ReportModel { ReportId = reportId, EmailSubject = report.GetEmailMessage().Subject };
     return View("ReportClient", model);
 }
Exemplo n.º 2
0
        public ActionResult GetReport(string reportId)
        {
            var sections = _emailReportService.GetSections();
            var report = _emailReportService.GetReportById(reportId);
            if (report.Email == null)
                throw new Exception("Email has not been received yet.");

            var model = new ReportModel { Sections = new List<SectionModel>(),  EmailSubject = report.GetEmailMessage().Subject };
            double reportSuccessGrade = 0;
            double reportTotalGrade = 0;
            foreach (var reportSection in sections)
            {
                var sectionsModel = new SectionModel { Topics = new List<TopicModel>(), Id = reportSection.Id, Title = reportSection.Title };
                double sectionSuccessGrade = 0;
                double sectionTotalGrade = 0;
                foreach (var topic in reportSection.Topics.OrderBy(x => x.Title))
                {
                    var rulesModel = (from rule in topic.ReportRules.Where(x => x.Enabled)
                                      let ruleResult = _emailReportService.ValidateRule(report, rule)
                                      select new RulesModel
                                                 {
                                                     ReturnMessage = ruleResult.Valid ? rule.SuccessMsg : rule.FailMsg,
                                                     Success = ruleResult.Valid,
                                                     RuleValue = rule.Weight
                                                 }).ToList();
                    sectionSuccessGrade += rulesModel.Where(x => x.Success).Sum(x => x.RuleValue);
                    sectionTotalGrade += rulesModel.Sum(x => x.RuleValue);
                    sectionsModel.Topics.Add(new TopicModel { Rules = rulesModel, Title = topic.Title, FromAddress = report.UserEmailAddress, Examples = topic.ExamplesLink, Tips = topic.MoreInfoLink, Resources = topic.AdditionalResources });
                }
                sectionsModel.Grade = ConvertPercentToLetterGrade(sectionSuccessGrade / sectionTotalGrade);
                reportSuccessGrade += sectionSuccessGrade*reportSection.Percentage;
                reportTotalGrade += sectionTotalGrade*reportSection.Percentage;
                model.Sections.Add(sectionsModel);
            }

            model.Score = ConvertPercentToLetterGrade(reportSuccessGrade/reportTotalGrade);

            return View("Report", model);
        }