Exemplo n.º 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++;
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void CopyRunoffAdvancers()
 {
     try
     {
         bool success;
         var  candidatesAdded   = 0;
         var  officesAdded      = 0;
         var  runoffElectionKey = GetElectionKey();
         if (!Elections.IsRunoffElection(runoffElectionKey))
         {
             throw new VoteException("This function may only be used with runoff elections.");
         }
         var runoffElectionDate =
             Elections.GetElectionDateFromKey(runoffElectionKey);
         var previousElectionDate = FeedbackMasterOnly.ValidateDate(
             ControlMasterOnlyElectionDateToCopy, out success,
             "Previous Election Date", runoffElectionDate.AddYears(-1),
             runoffElectionDate.AddDays(-7));
         if (!success)
         {
             return;
         }
         var offices =
             ElectionsPoliticians.GetRunoffAdvancersForElection(
                 runoffElectionKey, previousElectionDate)
             .GroupBy(r => r.OfficeKey);
         ElectionsOffices.DeleteByElectionKey(runoffElectionKey);
         ElectionsPoliticians.DeleteByElectionKey(runoffElectionKey);
         foreach (var o in offices)
         {
             var office = o.First();
             InsertElectionOffice(runoffElectionKey, office.OfficeKey);
             officesAdded++;
             foreach (var c in o)
             {
                 ElectionsPoliticians.Insert(runoffElectionKey, c.OfficeKey,
                                             c.PoliticianKey, c.RunningMateKey,
                                             Elections.GetStateElectionKeyFromKey(runoffElectionKey),
                                             string.Empty,
                                             Elections.GetCountyElectionKeyFromKey(runoffElectionKey),
                                             Elections.GetLocalElectionKeyFromKey(runoffElectionKey), c.StateCode,
                                             c.CountyCode, c.LocalCode, c.DistrictCode, 0, false,
                                             OfficesOfficials.OfficeKeyPoliticianKeyExists(c.OfficeKey,
                                                                                           c.PoliticianKey), false);
                 candidatesAdded++;
             }
         }
         FeedbackMasterOnly.AddInfo(
             $"{candidatesAdded} candidates were added, {officesAdded} offices were added.");
     }
     catch (Exception ex)
     {
         FeedbackMasterOnly.PostValidationError(ControlMasterOnlyPrimaryDateToCopy,
                                                "The candidates could not be copied: " + ex.Message);
     }
 }
Exemplo n.º 3
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();
            }
        }