Exemplo n.º 1
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);
     }
 }