Beispiel #1
0
        private static void MergePrimaryWinners(string generalElectionKey,
                                                DateTime primaryElectionDate, bool isRunoff, ref int candidateDuplicates,
                                                ref int candidatesAdded)
        {
            var offices = ElectionsPoliticians
                          .GetPrimaryWinnersForGeneralElection(generalElectionKey, primaryElectionDate,
                                                               isRunoff).GroupBy(r => r.OfficeKey);

            foreach (var o in offices)
            {
                foreach (var c in o)
                {
                    if (ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists(
                            generalElectionKey, c.OfficeKey, c.PoliticianKey))
                    {
                        candidateDuplicates++;
                    }
                    else
                    {
                        Elections.ActualizeElection(generalElectionKey);
                        ActualizeElectionOffice(generalElectionKey, c.OfficeKey);
                        ElectionsPoliticians.Insert(generalElectionKey, c.OfficeKey, c.PoliticianKey,
                                                    c.RunningMateKey, Elections.GetStateElectionKeyFromKey(generalElectionKey),
                                                    Empty, c.StateCode, c.CountyCode, c.LocalKey, c.DistrictCode, 0, false,
                                                    OfficesOfficials.OfficeKeyPoliticianKeyExists(c.OfficeKey, c.PoliticianKey),
                                                    false, Empty, null, null, null, Empty, false, DefaultDbDate, Empty, Empty, false);
                        candidatesAdded++;
                    }
                }
            }
        }
Beispiel #2
0
        private static void MergePrimaryWinners(string generalElectionKey,
                                                DateTime primaryElectionDate, bool isRunoff, ref int candidateDuplicates,
                                                ref int candidatesAdded /*, ref int candidatesSkippedOfficeMissing*/)
        {
            var offices = ElectionsPoliticians.GetPrimaryWinnersForGeneralElection(
                generalElectionKey, primaryElectionDate, isRunoff)
                          .GroupBy(r => r.OfficeKey);

            foreach (var o in offices)
            {
                //var office = o.First();
                //if (ElectionsOffices.ElectionKeyOfficeKeyExists(generalElectionKey,
                //  office.OfficeKey))
                foreach (var c in o)
                {
                    if (
                        ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists(
                            generalElectionKey, c.OfficeKey, c.PoliticianKey))
                    {
                        candidateDuplicates++;
                    }
                    else
                    {
                        Elections.ActualizeElection(generalElectionKey);
                        ActualizeElectionOffice(generalElectionKey, c.OfficeKey);
                        ElectionsPoliticians.Insert(generalElectionKey, c.OfficeKey,
                                                    c.PoliticianKey, c.RunningMateKey,
                                                    Elections.GetStateElectionKeyFromKey(generalElectionKey), string.Empty,
                                                    Elections.GetCountyElectionKeyFromKey(generalElectionKey),
                                                    Elections.GetLocalElectionKeyFromKey(generalElectionKey), c.StateCode,
                                                    c.CountyCode, c.LocalCode, c.DistrictCode, 0, false,
                                                    OfficesOfficials.OfficeKeyPoliticianKeyExists(c.OfficeKey,
                                                                                                  c.PoliticianKey), false);
                        candidatesAdded++;
                    }
                }
                //  else candidatesSkippedOfficeMissing += o.Count();
            }
        }
Beispiel #3
0
        protected void ButtonEditPolitician_OnClick(object sender, EventArgs e)
        {
            var toEdit        = GetPoliticianKeyToEdit();
            var politicianKey = toEdit.Key;

            CandidateHtml.Controls.Clear();
            var isRunningMate = !IsNullOrWhiteSpace(MainCandidateIfRunningMate.Value);

            if (Politicians.GetStateCodeFromKey(politicianKey) != "DC")
            {
                AddOnEditElement.AddCssClasses("hidden");
            }

            switch (EditPoliticianReloading.Value)
            {
            case "reloading":
            {
                EditPoliticianReloading.Value = Empty;
                ControlEditPoliticianPartyKey.Items.Clear();
                VotePage.LoadPartiesDropdown(Politicians.GetStateCodeFromKey(politicianKey),
                                             ControlEditPoliticianPartyKey, Empty, VotePage.PartyCategories.None,
                                             VotePage.PartyCategories.StateParties, VotePage.PartyCategories.NationalParties,
                                             VotePage.PartyCategories.NonParties);
                _EditPoliticianDialogInfo.LoadControls();
                FeedbackEditPolitician.AddInfo("Politician information loaded.");
                var href = SecurePoliticianPage.GetUpdateIntroPageUrl(politicianKey);
                UpdateIntroLink.HRef             = href;
                UpdateIntroLinkProfessional.HRef = href + "#bio2-ALLBio333333";
            }
            break;

            case "":
            {
                // normal update
                _EditPoliticianDialogInfo.ClearValidationErrors();
                _EditPoliticianDialogInfo.Update(FeedbackEditPolitician);
                var partyCodeToSuppress = Empty;
                if (isRunningMate)
                {
                    partyCodeToSuppress =
                        Parties.GetPartyCode(
                            Politicians.GetPartyKey(MainCandidateIfRunningMate.Value));
                }
                var row = Politicians.GetCandidateData(SafeGetElectionKey(), politicianKey,
                                                       isRunningMate);
                // use current dynamic IsIncumbent
                row["IsIncumbent"] = toEdit.ShowAsIncumbent;
                CandidateHtml.Controls.Add(CreateCandidateEntry(row, Mode, partyCodeToSuppress,
                                                                !isRunningMate && ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists(
                                                                    SafeGetElectionKey(), SafeGetOfficeKey(), politicianKey)));
            }
            break;

            default:
                throw new VoteException(
                          $"Unknown reloading option: '{EditPoliticianReloading.Value}'");
            }

            NameOnBallots.InnerText = PageCache.GetTemporary().Politicians
                                      .GetPoliticianName(politicianKey);
            UpdateIntroPage.SetPartyNameAndLink(ControlEditPoliticianPartyKey.GetValue(),
                                                PartyName);
        }
Beispiel #4
0
        private void Consolidate()
        {
            try
            {
                var key1Item        = _MasterOnlyTabInfo.Single(i => i.Column == "Key1");
                var key2Item        = _MasterOnlyTabInfo.Single(i => i.Column == "Key2");
                var jurisdictionKey = JurisdictionalKey;

                var success = true;

                success &= DataItemBase.ValidateRequired(key1Item);
                var key1Office = key1Item.DataControl.GetValue().Trim();

                success &= DataItemBase.ValidateRequired(key2Item);
                var key2Office = key2Item.DataControl.GetValue().Trim();

                if (success && key1Office.IsEqIgnoreCase(key2Office))
                {
                    key2Item.Feedback.PostValidationError(key2Item.DataControl, key2Item.Description +
                                                          " is identical to " + key1Item.Description);
                    success = false;
                }

                var officeKey1 = jurisdictionKey + key1Office;
                var officeKey2 = jurisdictionKey + key2Office;

                if (!success)
                {
                    return;
                }

                // do the consolidation
                var updateCount = 0;

                if (Offices.OfficeKeyExists(officeKey1))
                {
                    updateCount += Offices.DeleteByOfficeKey(officeKey2);
                }
                else
                {
                    updateCount += Offices.UpdateOfficeKey(officeKey1, officeKey2);
                }
                foreach (var row in ElectionsOffices.GetDataByOfficeKey(officeKey2))
                {
                    if (ElectionsOffices.ElectionKeyOfficeKeyExists(row.ElectionKey, officeKey1))
                    {
                        updateCount += ElectionsOffices.DeleteByElectionKeyOfficeKey(row.ElectionKey, officeKey2);
                    }
                    else
                    {
                        updateCount += ElectionsOffices.UpdateOfficeKeyByElectionKeyOfficeKey(officeKey1,
                                                                                              row.ElectionKey, officeKey2);
                    }
                }
                foreach (var row in ElectionsPoliticians.GetDataByOfficeKey(officeKey2))
                {
                    if (ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists(row.ElectionKey,
                                                                                     officeKey1, row.PoliticianKey))
                    {
                        updateCount += ElectionsPoliticians.DeleteByElectionKeyOfficeKeyPoliticianKey(
                            row.ElectionKey, officeKey2, row.PoliticianKey);
                    }
                    else
                    {
                        updateCount += ElectionsPoliticians.UpdateOfficeKeyByElectionKeyOfficeKeyPoliticianKey(
                            officeKey1, row.ElectionKey, officeKey2, row.PoliticianKey);
                    }
                }
                foreach (var row in OfficesOfficials.GetDataByOfficeKey(officeKey2))
                {
                    if (OfficesOfficials.OfficeKeyPoliticianKeyExists(officeKey1, row.PoliticianKey))
                    {
                        updateCount += OfficesOfficials.DeleteByOfficeKeyPoliticianKey(officeKey2,
                                                                                       row.PoliticianKey);
                    }
                    else
                    {
                        updateCount += OfficesOfficials.UpdateOfficeKeyByOfficeKeyPoliticianKey(officeKey1,
                                                                                                officeKey2, row.PoliticianKey);
                    }
                }
                foreach (var row in ElectionsIncumbentsRemoved.GetDataByOfficeKey(officeKey2))
                {
                    if (ElectionsIncumbentsRemoved.ElectionKeyOfficeKeyPoliticianKeyExists(row.ElectionKey,
                                                                                           officeKey1, row.PoliticianKey))
                    {
                        updateCount += ElectionsIncumbentsRemoved.DeleteByElectionKeyOfficeKeyPoliticianKey(
                            row.ElectionKey, officeKey2, row.PoliticianKey);
                    }
                    else
                    {
                        updateCount += ElectionsIncumbentsRemoved
                                       .UpdateOfficeKeyByElectionKeyOfficeKeyPoliticianKey(
                            officeKey1, row.ElectionKey, officeKey2, row.PoliticianKey);
                    }
                }
                updateCount += Politicians.UpdateOfficeKeyByOfficeKey(officeKey1, officeKey2);

                var msg = $"{updateCount} instances of the second office key {officeKey2} were found.";
                if (updateCount > 0)
                {
                    msg += $" They were all changed to the first office key {officeKey1}.";
                }
                FeedbackMasterOnly.AddInfo(msg);
                ResetMasterOnlySubTab(MasterOnlySubTab.Consolidate);
            }
            catch (Exception ex)
            {
                FeedbackMasterOnly.PostValidationError(ControlMasterOnlyNewKey,
                                                       "The office keys could not be consolidated: " + ex.Message);
            }
        }