public IHttpActionResult GetCity(int id) { City city = db.Cities.Find(id); if (city == null) { return(NotFound()); } DTO_City dcity = new DTO_City(); city.ConvertToDTO(dcity); return(Ok(dcity)); }
// GET: api/Cities public List <DTO_City> GetCities() { var cities = db.Cities; List <DTO_City> dcities = new List <DTO_City>(); foreach (City city in cities) { DTO_City dcity = new DTO_City(); city.ConvertToDTO(dcity); dcities.Add(dcity); } return(dcities); }
public List <DTO_City> GetCityByStateId(int id) { List <DTO_City> dcities = new List <DTO_City>(); List <City> cities = db.Cities.Where(x => x.State_Id == id).ToList(); foreach (City city in cities) { DTO_City dcity = new DTO_City(); city.ConvertToDTO(dcity); dcities.Add(dcity); } return(dcities); }
public void ConvertToDTO(DTO_City dcity) { dcity.City_Id = City_Id; dcity.City_Name = City_Name; dcity.State_Id = State_Id; }