Esempio n. 1
0
 public static OfficesTable GetOfficesByClass(string stateCode, string countyCode,
                                              string localKey, OfficeClass officeClass, int commandTimeout = -1)
 {
     if (IsNullOrWhiteSpace(localKey))
     {
         const string cmdText =
             "SELECT OfficeKey,StateCode,CountyCode,LocalKey,DistrictCode,OfficeLine1," +
             "OfficeLine2,OfficeLevel,IsRunningMateOffice,IsPrimaryRunningMateOffice,Incumbents,IsVacant FROM Offices" +
             " WHERE StateCode=@StateCode AND CountyCode=@CountyCode AND LocalKey='' AND OfficeLevel=@OfficeLevel AND IsVirtual=0" +
             " ORDER BY OfficeLine1,OfficeLine2";
         var cmd = VoteDb.GetCommand(cmdText, commandTimeout);
         VoteDb.AddCommandParameter(cmd, "StateCode", stateCode);
         VoteDb.AddCommandParameter(cmd, "CountyCode", countyCode);
         VoteDb.AddCommandParameter(cmd, "OfficeLevel", officeClass.ToInt());
         return(FillTable(cmd, OfficesTable.ColumnSet.Cache));
     }
     else
     {
         const string cmdText =
             "SELECT OfficeKey,StateCode,CountyCode,LocalKey,DistrictCode,OfficeLine1," +
             "OfficeLine2,OfficeLevel,IsRunningMateOffice,IsPrimaryRunningMateOffice,Incumbents,IsVacant FROM Offices" +
             " WHERE StateCode=@StateCode AND LocalKey=@LocalKey AND OfficeLevel=@OfficeLevel AND IsVirtual=0" +
             " ORDER BY OfficeLine1,OfficeLine2";
         var cmd = VoteDb.GetCommand(cmdText, commandTimeout);
         VoteDb.AddCommandParameter(cmd, "StateCode", stateCode);
         VoteDb.AddCommandParameter(cmd, "CountyCode", countyCode);
         VoteDb.AddCommandParameter(cmd, "LocalKey", localKey);
         VoteDb.AddCommandParameter(cmd, "OfficeLevel", officeClass.ToInt());
         return(FillTable(cmd, OfficesTable.ColumnSet.Cache));
     }
 }
Esempio n. 2
0
        private HtmlTableRow CreateOfficeHeading(OfficeClass officeClass,
                                                 string stateCode, string countyCode = "", string localCode = "")
        {
            var contestName =
                Offices.GetLocalizedOfficeClassDescription(officeClass, stateCode,
                                                           countyCode, localCode) + " Offices";

            Control officeHeading;

            if (!_DataManager.IsOfficeClassClosed(officeClass))
            {
                officeHeading = CreateOfficePageAnchor(stateCode, countyCode, localCode, officeClass,
                                                       "Add " + contestName);
            }
            else
            {
                officeHeading = new Literal {
                    Text = contestName
                }
            };

            var tr = new HtmlTableRow().AddCssClasses("trReportGroupHeadingLeft");
            var td = new HtmlTableCell {
                ColSpan = 2
            }.AddTo(tr, "tdReportGroupHeadingLeft");

            officeHeading.AddTo(td);

            return(tr);
        }
Esempio n. 3
0
        public static string GetDistrictItem(string stateCode,
                                             OfficeClass officeClass, string districtCode, int commandTimeout = -1)
        {
            const string cmdText =
                "SELECT DistrictCode,OfficeLine1,OfficeLine2 FROM Offices" +
                " WHERE StateCode=@StateCode AND OfficeLevel=@OfficeLevel" +
                " AND DistrictCode=@DistrictCode";

            if (districtCode.Length < 3)
            {
                districtCode = districtCode.ZeroPad(3);
            }
            var cmd = VoteDb.GetCommand(cmdText, commandTimeout);

            VoteDb.AddCommandParameter(cmd, "StateCode", stateCode);
            VoteDb.AddCommandParameter(cmd, "OfficeLevel", officeClass.ToInt());
            VoteDb.AddCommandParameter(cmd, "DistrictCode", districtCode);
            using (var cn = VoteDb.GetOpenConnection())
            {
                cmd.Connection = cn;
                var           table   = new DataTable();
                DbDataAdapter adapter = new MySqlDataAdapter(cmd as MySqlCommand);
                adapter.Fill(table);
                if (table.Rows.Count == 0)
                {
                    return(Empty);
                }
                var row = table.Rows[0];
                return(IsNullOrWhiteSpace(row.OfficeLine2())
          ? row.OfficeLine1()
          : row.OfficeLine2());
            }
        }
Esempio n. 4
0
        public IHttpActionResult PutOfficeClass(int id, OfficeClass officeClass)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != officeClass.Id)
            {
                return(BadRequest());
            }

            db.Entry(officeClass).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OfficeClassExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 5
0
        public static IEnumerable <SimpleListItem> GetDistrictItems(string stateCode,
                                                                    OfficeClass officeClass, int commandTimeout = -1)
        {
            const string cmdText =
                "SELECT DistrictCode,OfficeLine1,OfficeLine2 FROM Offices" +
                " WHERE StateCode=@StateCode AND OfficeLevel=@OfficeLevel" +
                " ORDER BY DistrictCode";

            var cmd = VoteDb.GetCommand(cmdText, commandTimeout);

            VoteDb.AddCommandParameter(cmd, "StateCode", stateCode);
            VoteDb.AddCommandParameter(cmd, "OfficeLevel", officeClass.ToInt());
            using (var cn = VoteDb.GetOpenConnection())
            {
                cmd.Connection = cn;
                var           table   = new DataTable();
                DbDataAdapter adapter = new MySqlDataAdapter(cmd as MySqlCommand);
                adapter.Fill(table);
                return(table.Rows.OfType <DataRow>()
                       .Select(row => new SimpleListItem
                {
                    Value = row.DistrictCode(),
                    Text = IsNullOrWhiteSpace(row.OfficeLine2())
              ? row.OfficeLine1()
              : row.OfficeLine2()
                }));
            }
        }
Esempio n. 6
0
        public async Task <IHttpActionResult> PutOfficeClass(int id, OfficeClass officeClass)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != officeClass.Id)
            {
                return(BadRequest());
            }

            db.Entry(officeClass).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OfficeClassExists(id))
                {
                    return(Content(HttpStatusCode.NotFound, "The Office with Id " + id + " does not exist "));
                    //return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 7
0
 public static OfficeClass AlternateOfficeClass(this DataRow row,
                                                OfficeClass defaultValue = Vote.OfficeClass.Undefined)
 {
     return(row.IsNull("AlternateOfficeLevel")
 ? defaultValue
 : Convert.ToInt32(row["AlternateOfficeLevel"]).ToOfficeClass());
 }
Esempio n. 8
0
 private string GetOfficeClassDescription(OfficeClass officeClass, bool shortDesc = false)
 =>
 (shortDesc
 ? Offices.GetShortLocalizedOfficeClassDescription(officeClass, StateCode, CountyCode,
                                                   LocalKey)
 : Offices.GetLocalizedOfficeClassDescription(officeClass, StateCode, CountyCode, LocalKey)) +
 " Politicians";
Esempio n. 9
0
 public static string GetOfficePageUrl(string stateCode, OfficeClass officeClass,
                                       string countyCode = "", string localKey = "")
 {
     return(GetAdminFolderPageUrl("office", "state", stateCode,
                                  "county", countyCode, "local", localKey,
                                  "class", officeClass.ToInt().ToString(CultureInfo.InvariantCulture)));
 }
        private static OfficeHeading GetOfficeHeading(OfficeClass officeClass, OfficeClass altClass)
        {
            switch (officeClass)
            {
            case OfficeClass.USPresident:
                return(OfficeHeading.President);

            case OfficeClass.USSenate:
                return(OfficeHeading.USSenate);

            case OfficeClass.USHouse:
                return(OfficeHeading.USHouse);

            case OfficeClass.StateWide:
                if (altClass == OfficeClass.USGovernors || altClass == OfficeClass.USLtGovernor ||
                    altClass == OfficeClass.DCMayor)
                {
                    return(OfficeHeading.Governor);
                }
                if (altClass == OfficeClass.DCShadowSenator)
                {
                    return(OfficeHeading.USSenate);
                }
                if (altClass == OfficeClass.DCShadowRepresentative)
                {
                    return(OfficeHeading.USHouse);
                }
                return(OfficeHeading.StateExecutive);

            case OfficeClass.StateSenate:
                return(OfficeHeading.StateSenate);

            case OfficeClass.StateHouse:
                return(OfficeHeading.StateHouse);

            case OfficeClass.CountyExecutive:
            case OfficeClass.CountyLegislative:
            case OfficeClass.CountySchoolBoard:
            case OfficeClass.CountyCommission:
            case OfficeClass.CountyJudicial:
            case OfficeClass.CountyParty:
                return(OfficeHeading.County);

            case OfficeClass.LocalExecutive:
            case OfficeClass.LocalLegislative:
            case OfficeClass.LocalSchoolBoard:
            case OfficeClass.LocalCommission:
            case OfficeClass.LocalJudicial:
            case OfficeClass.LocalParty:
                return(OfficeHeading.Local);

            case OfficeClass.StateJudicial:
            case OfficeClass.StateParty:
                return(OfficeHeading.StateExecutive);

            default:
                return(OfficeHeading.Other);
            }
        }
Esempio n. 11
0
        public static ElectoralClass GetElectoralClass(OfficeClass officeClass)
        {
            ElectoralClass electoralClass;

            return(ElectoralClassDictionary.TryGetValue(officeClass, out electoralClass)
        ? electoralClass
        : ElectoralClass.Unknown);
        }
Esempio n. 12
0
 private string GetOfficeClassDescription(OfficeClass officeClass, bool shortDesc = false)
 {
     return((shortDesc
 ? Offices.GetShortLocalizedOfficeClassDescription(officeClass, StateCode,
                                                   CountyCode, LocalKey)
 : Offices.GetLocalizedOfficeClassDescription(officeClass, StateCode,
                                              CountyCode, LocalKey)) + " Offices");
 }
Esempio n. 13
0
        private static void InsertOffice(ElectionsOfficesTable electionsOfficesTable,
                                         string electionKey, string officeKey, OfficeClass officeClass, string districtCode)
        {
            var stateCode = Elections.GetStateCodeFromKey(electionKey);

            electionsOfficesTable.AddRow(electionKey, officeKey, electionKey,
                                         Elections.GetFederalElectionKeyFromKey(electionKey, officeClass.StateCodeProxy()),
                                         stateCode, Empty, Empty, districtCode, officeClass.ToInt(), false);
        }
Esempio n. 14
0
        public IHttpActionResult GetOfficeClass(int id)
        {
            OfficeClass officeClass = db.OfficeClasses.Find(id);

            if (officeClass == null)
            {
                return(NotFound());
            }

            return(Ok(officeClass));
        }
Esempio n. 15
0
        public static OfficeClass OfficeClass(this DataRow row,
                                              OfficeClass defaultValue = Vote.OfficeClass.Undefined)
        {
            var column = row.Table.Columns.Contains("OfficeLevel")
        ? "OfficeLevel"
        : "OfficeClass";

            return(row.IsNull(column)
        ? defaultValue
        : Convert.ToInt32(row[column]).ToOfficeClass());
        }
Esempio n. 16
0
        public static string GetLocalizedOfficeClassDescription(
            OfficeClass officeClass, string stateCode, string countyCode,
            string localCode)
        {
            var desc = GetElectoralClassDescription(stateCode, countyCode, localCode);

            if (!StateCache.IsValidFederalCode(stateCode))
            {
                desc += " " + GetOfficeClassDescription(officeClass, stateCode);
            }
            return(desc);
        }
Esempio n. 17
0
        public async Task <IHttpActionResult> PostOfficeClass(OfficeClass officeClass)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.OfficeClasses.Add(officeClass);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = officeClass.Id }, officeClass));
        }
Esempio n. 18
0
        private static HtmlAnchor CreateOfficePageAnchor(string stateCode, string countyCode,
                                                         string localKey, OfficeClass officeClass, string text)
        {
            var a = new HtmlAnchor
            {
                HRef      = SecureAdminPage.GetUpdateOfficesPageUrl(stateCode, countyCode, localKey, officeClass),
                Target    = "office",
                InnerHtml = text
            };

            return(a);
        }
Esempio n. 19
0
        public static bool IsFederal(this OfficeClass officeClass)
        {
            switch (officeClass)
            {
            case OfficeClass.USPresident:
            case OfficeClass.USSenate:
            case OfficeClass.USHouse:
                return(true);

            default:
                return(false);
            }
        }
Esempio n. 20
0
        public IHttpActionResult DeleteOfficeClass(int id)
        {
            OfficeClass officeClass = db.OfficeClasses.Find(id);

            if (officeClass == null)
            {
                return(NotFound());
            }

            db.OfficeClasses.Remove(officeClass);
            db.SaveChanges();

            return(Ok(officeClass));
        }
Esempio n. 21
0
        public async Task <IHttpActionResult> DeleteOfficeClass(int id)
        {
            OfficeClass officeClass = await db.OfficeClasses.FindAsync(id);

            if (officeClass == null)
            {
                return(NotFound());
            }

            db.OfficeClasses.Remove(officeClass);
            await db.SaveChangesAsync();

            return(Ok(officeClass));
        }
Esempio n. 22
0
        public static OfficesTable GetOfficeTemplatesByClass(string stateCode, OfficeClass officeClass,
                                                             int commandTimeout = -1)
        {
            const string cmdText =
                "SELECT OfficeKey,StateCode,CountyCode,LocalCode,DistrictCode,OfficeLine1," +
                "OfficeLine2,OfficeLevel,IsRunningMateOffice,Incumbents,IsVacant FROM Offices" +
                " WHERE StateCode=@StateCode AND OfficeLevel=@OfficeLevel AND IsVirtual=1" +
                " ORDER BY OfficeLine1,OfficeLine2";
            var cmd = VoteDb.GetCommand(cmdText, commandTimeout);

            VoteDb.AddCommandParameter(cmd, "StateCode", stateCode);
            VoteDb.AddCommandParameter(cmd, "OfficeLevel", officeClass.ToInt());
            return(FillTable(cmd, OfficesTable.ColumnSet.Cache));
        }
Esempio n. 23
0
        public async Task <IHttpActionResult> GetOfficeClass(int id)
        //public async Task<HttpResponseMessage> GetOfficeClass(int id)
        {
            OfficeClass officeClass = await db.OfficeClasses.FindAsync(id);

            if (officeClass == null)
            {
                //return Request.CreateErrorResponse(HttpStatusCode.NotFound, "The Office with Id " + id + " does not exist ");

                return(Content(HttpStatusCode.NotFound, "The Office with Id " + id + " does not exist "));
                //return NotFound();
            }

            //return Request.CreateResponse(HttpStatusCode.OK, officeClass);
            return(Ok(officeClass));
        }
        // ReSharper disable MemberCanBePrivate.Global
        // ReSharper disable MemberCanBeProtected.Global
        // ReSharper disable UnusedMember.Global
        // ReSharper disable UnusedMethodReturnValue.Global
        // ReSharper disable UnusedAutoPropertyAccessor.Global

        public static int CountData(
            OfficesAdminReportViewOption option = OfficesAdminReportViewOption.None,
            OfficeClass officeClass             = OfficeClass.All, string stateCode = "",
            string countyCode = "", string localCode = "", int commandTimeout = -1)
        {
            var options = new OfficesAdminReportViewOptions
            {
                Option      = option,
                OfficeClass = officeClass,
                StateCode   = stateCode,
                CountyCode  = countyCode,
                LocalCode   = localCode
            };

            return(CountData(options, commandTimeout));
        }
Esempio n. 25
0
        public static string StateCodeProxy(this OfficeClass officeClass)
        {
            switch (officeClass)
            {
            case OfficeClass.USPresident:
                return("U1");

            case OfficeClass.USSenate:
                return("U2");

            case OfficeClass.USHouse:
                return("U3");

            case OfficeClass.USGovernors:
                return("U4");

            default:
                return(string.Empty);
            }
        }
Esempio n. 26
0
        private string GetOfficeClassLinkOrText(string stateCode,
                                                OfficeClass officeClass, bool allIdentified, string countyCode = "",
                                                string localCode = "")
        {
            var text = GetOfficeClassDescription(officeClass);

            if (allIdentified)
            {
                return(text);
            }

            var a = new HtmlAnchor
            {
                HRef      = GetOfficePageUrl(stateCode, officeClass, countyCode, localCode),
                Target    = "office",
                InnerHtml = text
            };

            return(a.RenderToString());
        }
Esempio n. 27
0
        public static bool CanAddOfficesToOfficeClass(OfficeClass officeClass,
                                                      string stateCode)
        {
            switch (officeClass)
            {
            case OfficeClass.All:
            case OfficeClass.USPresident:
            case OfficeClass.USSenate:
            case OfficeClass.USHouse:
                return(false);

            case OfficeClass.StateSenate:
                return(stateCode == "DC");

            case OfficeClass.StateHouse:
                return(stateCode == "DC");

            default:
                return(true);
            }
        }
Esempio n. 28
0
 public static string ShortDescription(this OfficeClass officeClass,
                                       string stateCode = null)
 {
     return(Offices.GetOfficeClassShortDescription(officeClass, stateCode));
 }
Esempio n. 29
0
        public static string GetOfficeClassDescription(OfficeClass officeClass,
                                                       string stateCode = null)
        {
            switch (officeClass)
            {
            case OfficeClass.Undefined:
                return("Undefined");

            case OfficeClass.All:
                return("All");

            case OfficeClass.USPresident:
                return("U.S. President");

            case OfficeClass.USSenate:
                return("U.S. Senate");

            case OfficeClass.USHouse:
                return("U.S. House of Representatives");

            case OfficeClass.USGovernors:
                return("State Governors");

            case OfficeClass.StateWide:
                return(stateCode == "DC"
            ? "Citywide Non-Judicial"
            : "Statewide Non-Judicial [like Governor, Treasurer...]");

            case OfficeClass.StateSenate:
                return(stateCode == "DC" ? "Wards" : "State Senate");

            case OfficeClass.StateHouse:
                return(stateCode == "DC" ? "ANCs" : "State House");

            case OfficeClass.StateDistrictMultiCounties:
                return(stateCode == "DC"
            ? "Multi-ANC Non-Judicial"
            : "Multi-County Non-Judicial");

            case OfficeClass.CountyExecutive:
                return
                    ("County EXECUTIVE [like Executive , Mayor, Sheriff, Treasurer, Clerk...]");

            case OfficeClass.CountyLegislative:
                return("County LEGISLATIVE [like Councils, Board of Supervisors...]");

            case OfficeClass.CountySchoolBoard:
                return("County SCHOOL & COLLEGE BOARDS");

            case OfficeClass.CountyCommission:
                return
                    ("County Special COMMISSION and Committees [like Parks, Soil, Water...]");

            case OfficeClass.LocalExecutive:
                return
                    ("Local EXECUTIVE [like Executive , Mayor, Sheriff, Treasurer, Clerk...]");

            case OfficeClass.LocalLegislative:
                return("Local LEGISLATIVE [like Councils, Board of Supervisors...]");

            case OfficeClass.LocalSchoolBoard:
                return("Local SCHOOL & COLLEGE BOARDS");

            case OfficeClass.LocalCommission:
                return
                    ("Local Special COMMISSION and Committees [like Parks, Soil, Water...]");

            case OfficeClass.StateJudicial:
                return(stateCode == "DC" ? "Citywide JUDICIAL" : "Statewide JUDICIAL");

            case OfficeClass.StateDistrictMultiCountiesJudicial:
                return("JUDICIAL District");

            case OfficeClass.CountyJudicial:
                return("County JUDICIAL");

            case OfficeClass.LocalJudicial:
                return("Local JUDICIAL");

            case OfficeClass.StateParty:
                return(stateCode == "DC"
            ? "Political PARTY"
            : "Statewide Political PARTY");

            case OfficeClass.StateDistrictMultiCountiesParty:
                return(stateCode == "DC"
            ? "Local Political PARTY"
            : "Multi-County Political PARTY");

            case OfficeClass.CountyParty:
                return("County Political PARTY");

            case OfficeClass.LocalParty:
                return("Local Political PARTY");

            default:
                return("Undefined");
            }
        }
Esempio n. 30
0
        public static string GetOfficeClassShortDescription(OfficeClass officeClass,
                                                            string stateCode = null)
        {
            switch (officeClass)
            {
            case OfficeClass.Undefined:
                return("Undefined");

            case OfficeClass.All:
                return("All");

            case OfficeClass.USPresident:
                return("U.S. President");

            case OfficeClass.USSenate:
                return("U.S. Senate");

            case OfficeClass.USHouse:
                return("U.S. House");

            case OfficeClass.USGovernors:
                return("Governor");

            case OfficeClass.StateWide:
                return(stateCode == "DC"
            ? "Citywide"
            : "Statewide");

            case OfficeClass.StateSenate:
                return(stateCode == "DC" ? "Wards" : "State Senate");

            case OfficeClass.StateHouse:
                return(stateCode == "DC" ? "ANCs" : "State House");

            case OfficeClass.StateDistrictMultiCounties:
                return(stateCode == "DC"
            ? "Multi-ANC"
            : "Multi-County");

            case OfficeClass.CountyExecutive:
                return
                    ("County Executive");

            case OfficeClass.CountyLegislative:
                return("County Legislative");

            case OfficeClass.CountySchoolBoard:
                return("County School Board");

            case OfficeClass.CountyCommission:
                return
                    ("County Special Commissions/Committees");

            case OfficeClass.LocalExecutive:
                return
                    ("Local Executive");

            case OfficeClass.LocalLegislative:
                return("Local Legislative");

            case OfficeClass.LocalSchoolBoard:
                return("Local School Board");

            case OfficeClass.LocalCommission:
                return
                    ("Local Special Commisions/Committees");

            case OfficeClass.StateJudicial:
                return(stateCode == "DC" ? "Citywide Judicial" : "Statewide Judicial");

            case OfficeClass.StateDistrictMultiCountiesJudicial:
                return("Judicial District");

            case OfficeClass.CountyJudicial:
                return("County Judicial");

            case OfficeClass.LocalJudicial:
                return("Local Judicial");

            case OfficeClass.StateParty:
                return(stateCode == "DC"
            ? "Citywide Party"
            : "Statewide Party");

            case OfficeClass.StateDistrictMultiCountiesParty:
                return(stateCode == "DC"
            ? "Local Party"
            : "Multi-County Party");

            case OfficeClass.CountyParty:
                return("County Party");

            case OfficeClass.LocalParty:
                return("Local Party");

            default:
                return("Undefined");
            }
        }