This site only queries a database - NO CRUD
I have a Service DLL that I call from a ApiController
the ApiController
methods are called by ajax requests in my HTML.
My problem is it's getting pretty hairy in my service. Here are just a few examples of the method stubs. I have more methods than this. Then it get's even hairy as I have to wrap every service call in my APIController
.
Service
public IEnumerable<CodedValue> GetStreetSuffix()
{
using (var s = new SqlConnection(this.connection))
{
s.Open();
var results = s.Query<CodedValue>(
@"SELECT DISTINCT STR_SFX Value,STR_SFX Code FROM Addresses ORDER BY 1").ToList();
return results;
}
}
public IEnumerable<dynamic> GetStreetNumbers(string term)
{
using (var s = new SqlConnection(this.connection))
{
s.Open();
var results = s.Query<dynamic>(
@"SELECT DISTINCT STR_NUM FROM Addresses where ISNULL(RTRIM(STR_PFX) + ' ','') + RTRIM(STR) + ISNULL(' ' + STR_SFX,'') = @q", new { q = term }).ToList();
return results;
}
}
APIController
[HttpGet]
public IEnumerable<dynamic> ListStreetNumbers(string term)
{
var searchservice = new SearchService();
var results = searchservice.GetStreetNumbers(term);
return results;
}
[HttpGet,HttpPost]
public IEnumerable<dynamic> CountParcelsByAddresses(Address json)
{
var searchservice = new SearchService();
var results = searchservice.CountParcelsByAddress(json);
return results;
}
What can I do to make this cleaner while not abstracting the hell out of it. Most of what I did was trying to avoid having SQL queries in my controllers or in my HTML.