Ejemplo n.º 1
0
            protected override bool Update(object newValue)
            {
                var changed = false;
                //Parse the value from the UI tree
                var valueStr = newValue as string;

                if (valueStr == null)
                {
                    return(false);
                }
                var offices = valueStr.Split(new[] { '|' },
                                             StringSplitOptions.RemoveEmptyEntries)
                              .Select(officeStr =>
                {
                    var officeSplit = officeStr.Split(':');
                    return
                    (new
                    {
                        OfficeKey = officeSplit[0],
                        Incumbents = officeSplit[1].Split(',')
                    });
                })
                              .ToArray();

                foreach (var office in offices)
                {
                    var table         = OfficesOfficials.GetDataByOfficeKey(office.OfficeKey);
                    var officeChanged = false;
                    foreach (var row in table)
                    {
                        if (!office.Incumbents.Contains(row.PoliticianKey))
                        {
                            if (!ElectionsIncumbentsRemoved.ElectionKeyOfficeKeyPoliticianKeyExists
                                    (Page.GetElectionKey(), row.OfficeKey, row.PoliticianKey))
                            {
                                ElectionsIncumbentsRemoved.Insert(Page.GetElectionKey(), row.OfficeKey,
                                                                  row.PoliticianKey, row.RunningMateKey, row.StateCode,
                                                                  row.CountyCode, row.LocalCode, row.DistrictCode,
                                                                  //row.LDSVersion, row.LDSUpdateDate,
                                                                  row.DataLastUpdated, row.UserSecurity,
                                                                  row.UserName);
                            }
                            row.Delete();
                            officeChanged = true;
                        }
                    }
                    if (!officeChanged)
                    {
                        continue;
                    }
                    OfficesOfficials.UpdateTable(table);
                    changed = true;
                }

                //LoadControl();
                return(changed);
            }
Ejemplo n.º 2
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);
            }
        }