Using Northwind database I can search through the tables via an Int id which is fine but on the customer table, the Customer ID is a string, my api controller won't run if I try and search for a customer entering a specific string I can return all but not an individual how can I tell the controller to search for a string id ie Joe Bloggs CustId=NVAMD ?
[RoutePrefix("api/cust")]
[RoutePrefix("api/cust")]
public class CustomersController : ApiController
{
private NORTHWNDEntities db = new NORTHWNDEntities();
[Route("getall")]
// GET: api/Customers
public IQueryable<Customer> GetCustomers()
{
return db.Customers;
}
// GET: api/Customers/5
[ResponseType(typeof(Customer))]
[Route("getcustid/{id:string}")]
public dynamic GetCustomer(string id)
{
Customer customer = db.Customers.Find(id);
if (customer == null)
{
return NotFound();
}
return Ok(customer);
}
[Route("getcustadd/{id:string}")]
public dynamic GetCust(string id)
{
Customer cust = db.Customers.Find(id);
if (cust == null)
return NotFound();
return Ok(cust);
}