示例#1
0
        public static Control GetReport(string electionKey)
        {
            var reportObject = new Election2ReportResponsive();

            return(reportObject.GenerateReport(electionKey));
        }
示例#2
0
            public void Generate(Election2ReportResponsive electionReport, string electionKey,
                                 bool isForAllStatesReport = false)
            {
                ElectionReport = electionReport;
                ElectionKey    = electionKey;
                StateCode      = Elections.GetStateCodeFromKey(electionKey);
                CountyCode     = Elections.GetCountyCodeFromKey(electionKey);
                LocalKey       = Elections.GetLocalKeyFromKey(electionKey);
                var counties           = LocalIdsCodes.FindCountiesWithNames(StateCode, LocalKey);
                var isMultiCountyLocal = counties.Length > 1;

                IsForAllStatesReport = isForAllStatesReport;

                var offices = GetOffices()
                              .Where(g => g.First().ElectionsPoliticianKey() != null)
                              .ToList();

                if (offices.Count <= 0)
                {
                    return;
                }
                if (Elections.IsPrimaryElection(electionKey))
                {
                    offices = FilterUncontestedOffices(offices)
                              .ToList();
                }

                Control container;

                // only create a category wrapper if more than one office, or isMultiCountyLocal
                if (isMultiCountyLocal || offices.Count > 1 || isForAllStatesReport)
                {
                    // ReSharper disable once PossibleNullReferenceException
                    var title = new PlaceHolder();
                    // ReSharper disable once PossibleNullReferenceException
                    (new HtmlSpan().AddTo(title) as HtmlGenericControl).InnerText = GetCategoryTitle();
                    if (isMultiCountyLocal)
                    {
                        var allCounties =
                            LocalIdsCodes.FormatAllCountyNames(StateCode, LocalKey, true);
                        // ReSharper disable once PossibleNullReferenceException
                        (new HtmlP().AddTo(title) as HtmlGenericControl)
                        .InnerText = $"Parts of this local district are in {allCounties}";
                    }
                    // ReSharper disable once PossibleNullReferenceException
                    new HtmlDiv().AddTo(ElectionReport.ReportContainer, "category-title accordion-header")
                    .Controls.Add(title);
                    container = new HtmlDiv().AddTo(ElectionReport.ReportContainer,
                                                    "category-content accordion-content");
                }
                else
                {
                    container = ElectionReport.ReportContainer;
                }

                foreach (var office in offices)
                {
                    var politicians = office.ToList();
                    var officeInfo  = politicians[0];

                    var officeContent = new HtmlDiv();
                    CreateOfficeTitle(container, officeContent, politicians,
                                      GetOfficeTitle(officeInfo));
                    officeContent.AddTo(container, "office-content accordion-content");
                    //var isRunningMateOffice = officeInfo.IsRunningMateOffice() &&
                    //  !Elections.IsPrimaryElection(electionKey);
                    var isRunningMateOffice = Offices.IsRunningMateOfficeInElection(electionKey,
                                                                                    officeInfo.OfficeKey());
                    ReportOffice(officeContent, isRunningMateOffice, politicians,
                                 ElectionReport._DataManager);
                }
            }