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

I have a web-api application that has a posts to a database table in my localDB. I want to make the client (right now using postman) to select which table it will be posting to using a query string. I know that post method only accepts one post parameter so I want to pass just one but with multiple selective models in it. (not sure if I explained that right)

Basically I just want to combine JT JT and sales sales into one parameter and use it in my entity add() method. But I don't have an idea how.

Here's my sample code.

C#
[HttpPost]
        public HttpResponseMessage PostJT(JT JT, Sales Sales, [FromUri] string tran)
//I want to combine JT JT, and sales sales
        {

            //JT JT = new JT();
            //Sales Sales = new Sales();

            try
            {
                if (ModelState.IsValid)
                {
                                switch (tran)
                                {
                                    case "JT":
                                        db.JTs.Add(JT);
                                        db.SaveChanges();
                                        break;
                                    case "sales":
                                        db.Sales_.Add(Sales);
                                        db.SaveChanges();
                                        break;
                                }
                            }
                            return Request.CreateErrorResponse(HttpStatusCode.OK, "Added!");
                        }
                    }
                    else
                    {
                        return Request.CreateResponse(HttpStatusCode.Unauthorized, "Unauthorized Access!");
                    }
                }
                
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }

        }


Hopefully, someone helps me. I'm still getting the hang of web-api.
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