// GET api/values/5 public IEnumerable <string> Get(int id) { List <string> hwList = new List <string>(); //use this one to interact with the database, and create a POCO class that can be used for EF if (id.Equals(0)) { using (CroweHellowWorldDBEntities entities = new CroweHellowWorldDBEntities()) { var slist = entities.HWs.ToList(); foreach (var item in slist) { hwList.Add(item.Name); } return(hwList); } } else { using (CroweHellowWorldDBEntities entities = new CroweHellowWorldDBEntities()) { var chw = entities.HWs.FirstOrDefault(p => p.ID == id); hwList.Add(chw.Name); } return(hwList); } }
// GET api/values/5 public IEnumerable <string> Get(int id) { List <string> hwList = new List <string>(); //use this one to interact with the database, and create a POCO class that can be used for EF if (id.Equals(0)) { using (CroweHellowWorldDBEntities entities = new CroweHellowWorldDBEntities()) { var slist = entities.HWs.ToList(); if (slist == null) { string message = "Table doesnt have any data"; throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); } foreach (var item in slist) { hwList.Add(item.Name); } return(hwList); } } else { using (CroweHellowWorldDBEntities entities = new CroweHellowWorldDBEntities()) { var chw = entities.HWs.FirstOrDefault(p => p.ID == id); if (chw == null) { string message = "ID doesnt match what is in the table"; throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); } else { hwList.Add(chw.Name); } } return(hwList); } }
// GET api/values/5 public IEnumerable <HW> Get(int id) { //use this one to interact with the database, and create a POCO class that can be used for EF if (id.Equals(0)) { using (CroweHellowWorldDBEntities entities = new CroweHellowWorldDBEntities()) { return(entities.HWs.ToList()); } } else { List <HW> hwList = new List <HW>(); using (CroweHellowWorldDBEntities entities = new CroweHellowWorldDBEntities()) { var chw = entities.HWs.FirstOrDefault(p => p.ID == id); hwList.Add(chw); //var chwlist = entities.HWs.ToList(); ; } return(hwList); } }