// GET api/values public HttpResponseMessage Get(string dataBase = "DefaultConnection") { HttpResponseMessage response; try { using (var db = new SqlConnection(ConfigurationManager.ConnectionStrings[dataBase].ConnectionString)) { var agentList = new List <AGENT_CAMP>(); var cmd = new SqlCommand("SELECT * FROM AGENT_CAMP where ACTIVE_SW = 1 and END_DATE is null", db); db.Open(); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { agentList.Add(BuildAgentObject(rdr)); } } var testResult = new SampleReturn { data = agentList }; response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(testResult)); } } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.InternalServerError); response.Content = new StringContent(JsonConvert.SerializeObject(ex)); } return(response); }
public HttpResponseMessage Get(int agentCampId, string dataBase = "DefaultConnection") { HttpResponseMessage response; try { using (var db = new SqlConnection(ConfigurationManager.ConnectionStrings[dataBase].ConnectionString)) { var agentCampCriteria = new List <AGENT_CAMP_CRITERIA>(); var cmd = new SqlCommand("SELECT * FROM AGENT_CAMP_CRITERIA where AGENT_CAMP_ID = " + agentCampId, db); db.Open(); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { agentCampCriteria.Add(new AGENT_CAMP_CRITERIA() { AGENT_CAMP_CRITERIA_ID = (int)rdr["AGENT_CAMP_CRITERIA_ID"], AGENT_CAMP_ID = (int)rdr["AGENT_CAMP_ID"], PERCENT_APPLIED = (int)rdr["PERCENT_APPLIED"], QUERY = rdr["QUERY"].ToString() }); } } var result = agentCampCriteria; var testResult = new SampleReturn { data = agentCampCriteria }; response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(testResult)); } } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.InternalServerError); response.Content = new StringContent(JsonConvert.SerializeObject(ex)); } return(response); }