Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a web-api post method that will save data from Json via postman to an SQL table. Now I need it to choose where to save the data using a parameter from the uri. Now I have this code currently:

C#
private AH_ODS_DB_Entities db = new AH_ODS_DB_Entities();

[ResponseType(typeof(JT))]
public HttpResponseMessage PostJT(JT JT, Sales Sales, [FromUri] string auth, [FromUri] string tran)
{
    try
    {
        if (ModelState.IsValid)
        {
                    if (tran == null)
                    {
                        return Request.CreateResponse(HttpStatusCode.Unauthorized, "Unauthorized Access!");
                    }
                    else
                    {
                        switch (tran)
                        {
                            case "JT": db.JTs.Add(JT);
                                break;
                            case "sales": db.Sales_.Add(Sales);
                                break;
                        }
                    }
                    //db.SaveChanges();
                    return Request.CreateErrorResponse(HttpStatusCode.OK, "Added!");
                }
//just elses below


Unfortunately I am getting an error "can't bind multiple parameters to the request's content web api".

It goes like this: If I post with the uri parameter ?tran=JT, it should add data to the JT table in my sql DB. likewise if ?tran=sales then it posts to the sales table. Can anyone help me?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900