I am trying to pass a parameter from my API, but it does not seem to be taking it. I have a lastName (eventually will be replaced with a unique id) that I want to pass, which will ultimately route to a profile view or that person.
Here is my API Controller:
public class GetInquiryController : BaseController
{
private GetInquiry manager;
public GetInquiryController(IConfiguration config) : base(config)
{
manager = new GetInquiry(config);
}
[HttpGet]
[Route("api/[controller]")]
public IEnumerable<InquiryModel> Get(string lastName)
{
return manager.GetInquiriesByUser(lastName);
}
}
And my logic for my stored procedure that gets the last name
public class GetInquiry
{
private readonly IConfiguration configuration;
public GetInquiry(IConfiguration config)
{
configuration = config;
}
public IEnumerable<InquiryModel> GetInquiriesByUser(string lastName)
{
string ApplicationDB = configuration.GetConnectionString("ApplicationDB");
List<InquiryModel> lstinquiry = new List<InquiryModel>();
using (SqlConnection con = new SqlConnection(ApplicationDB))
{
SqlCommand cmd = new SqlCommand("spGetInquiriesByUser", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter lastNameParameter = cmd.Parameters.Add("lastName", SqlDbType.Char, 10);
lastNameParameter.Value = lastName;
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
InquiryModel inquiry = new InquiryModel();
//inquiry.FormID = rdr["FormID"].ToString();
inquiry.firstName = rdr["firstName"].ToString();
inquiry.lastName = rdr["lastName"].ToString();
inquiry.SID = rdr["SID"].ToString();
inquiry.email = rdr["email"].ToString();
inquiry.phone = rdr["phone"].ToString();
inquiry.email = rdr["email"].ToString();
inquiry.employer = rdr["street"].ToString();
inquiry.city = rdr["city"].ToString();
inquiry.state = rdr["state"].ToString();
inquiry.zip = rdr["zip"].ToString();
inquiry.date = rdr["date"].ToString();
inquiry.comment = rdr["comment"].ToString();
lstinquiry.Add(inquiry);
}
con.Close();
}
return lstinquiry;
}
}
}
I am using VUE.js and calling my API
methods: {
editItem(lastName) {
let id = lastName
this.$http.get('http://localhost:61601/api/GetInquiry/', {
id: lastName
}),
I have tried using my logic without IEnumerable, which i didn't think will make a difference in this case.
I guess the good thing is that I am getting,
"SqlException: Procedure or function 'spGetInquiriesByUser' expects parameter '@lastName', which was not supplied"
when type my API route into the browser, but when I add the lastName to the end of my route or Postman, I get a blank page.
Hope this makes sense, please let me know if i need to provide more detail and if someone can point me into the right direction!