mercredi 30 septembre 2020

How to send Id and retrieve data related to that ID from database using Web API in .Net

I want to send CatID as user from client side and in server side I need to accept that and send back response to the client catName,catDes,catPic relevant to entered ID.

Below code is used to send Data to client. I want to receive req. from client and send back relevant response to client, this needs to done via Web API.

public class AddcatController : ApiController {

    [HttpPost]

    public HttpResponseMessage PostCat(Catergory category)
    {
        using (var db = new NorthwindEntities())
        {
            db.Categories.Add(new Category()
            {
                CategoryID = category.catId,
                CategoryName = category.catName,
                Description = category.catDes,
                Picture = category.catPic


            });

            db.SaveChanges();

        }
        //return OK;
        return Request.CreateResponse(HttpStatusCode.OK);
    }  }



Aucun commentaire:

Enregistrer un commentaire