示例#1
0
            private void LoadControlManageIncumbents()
            {
                var officeKey = _ThisControl.SafeGetOfficeKey();

                var table = OfficesOfficials.GetIncumbentsForOffice(officeKey);
                int incumbentsAllowed;
                var incumbents = table.Rows.Cast <DataRow>() // these are pre-sorted
                                 .Where(row => !row.IsRunningMate())
                                 .ToList();

                _ThisControl.PageFeedback.AddInfo(
                    $"{incumbents.Count} incumbent{incumbents.Count.Plural()} loaded.");
                if (incumbents.Count == 0)
                {
                    _ThisControl.Message.RemoveCssClass("hidden");
                    _ThisControl.Message.InnerHtml =
                        "No incumbents were found for this office.";
                    incumbentsAllowed = Offices.GetIncumbents(officeKey, 0);
                }
                else
                {
                    _ThisControl.Message.AddCssClasses("hidden");
                    foreach (var incumbent in incumbents)
                    {
                        var li =
                            new HtmlLi
                        {
                            ID           = "candidate-" + incumbent.PoliticianKey(),
                            ClientIDMode = ClientIDMode.Static
                        }.AddTo(
                            _ThisControl.ControlAddCandidatesCandidateList);
                        var outerDiv = new HtmlDiv().AddTo(li, "outer shadow-2");
                        CreateCandidateEntry(incumbent, DataMode.ManageIncumbents)
                        .AddTo(outerDiv);
                        var runningMateKey = incumbent.RunningMateKey();
                        if (!incumbent.IsRunningMateOffice())
                        {
                            continue;
                        }
                        DataRow runningMate = null;
                        if (!string.IsNullOrWhiteSpace(runningMateKey))
                        {
                            runningMate = table.Rows.Cast <DataRow>()
                                          .FirstOrDefault(row => row.PoliticianKey()
                                                          .IsEqIgnoreCase(runningMateKey));
                        }
                        if (runningMate == null)
                        {
                            CreateNoRunningMateEntry()
                            .AddTo(outerDiv);
                        }
                        else
                        {
                            CreateCandidateEntry(runningMate, DataMode.ManageIncumbents, incumbent.PartyCode())
                            .AddTo(outerDiv);
                        }
                    }
                    incumbentsAllowed = incumbents.First().Incumbents();
                }
                _ThisControl.IncumbentCountMessage.InnerText = incumbentsAllowed == 1
          ? "This office can have only a single incumbent"
          : $"This office can have {incumbentsAllowed} incumbents";
                _ThisControl.IncumbentCountMessage.Visible = true;
                _ThisControl.IncumbentCount.Value          = incumbentsAllowed.ToString(CultureInfo.InvariantCulture);
                _ThisControl.IncumbentCount.Visible        = true;
            }