public static PoliticianOfficeStatus GetOfficeStatus(string politicianKey) { const string cmdText = "CALL OfficeStatus(@PoliticianKey)"; var cmd = VoteDb.GetCommand(cmdText, -1); VoteDb.AddCommandParameter(cmd, "PoliticianKey", politicianKey); var table = new DataTable(); using (var cn = VoteDb.GetOpenConnection()) { cmd.Connection = cn; var adapter = VoteDb.GetDataAdapter(cmd); adapter.Fill(table); } var status = table.Rows[0]["Status"].ToString(); PoliticianStatus policicianStatus; if (!Enum.TryParse(status, out policicianStatus)) { policicianStatus = PoliticianStatus.Unknown; } var result = new PoliticianOfficeStatus { OfficeKey = table.Rows[0]["OfficeKey"].ToString(), PoliticianStatus = policicianStatus }; return(result); }
public static PoliticianOfficeStatus FromLiveOfficeKeyAndStatus( string liveOfficeKeyAndStatus) { var result = new PoliticianOfficeStatus(); var split = liveOfficeKeyAndStatus.Split('|'); if (split.Length >= 2) { result.OfficeKey = split[0]; if (!Enum.TryParse(split[1], out result.PoliticianStatus)) { result.PoliticianStatus = PoliticianStatus.Unknown; } result.ElectionKey = split.Length > 2 ? split[2] : string.Empty; } else { result.OfficeKey = string.Empty; result.ElectionKey = string.Empty; result.PoliticianStatus = PoliticianStatus.Unknown; } return(result); }