In MVC while working in API for making restful services you need to know your request and response.
You can pass data or entity from your model as you want.

But in any case, you have a requirement of passing multiple records as the request or response then what you need to do is create a list in the model class.
See the example below:
public class ProductModel
{
public int Id { get; set; }
public string ProductName { get; set; }
}
After that you can pass that list into your response for getting all the rows that comes from the database in case of response, as in below example:
public class ProductResponse
{
public List<ProductModel> ProductList { get; set; }
public bool Status { get; set; }
public string Message { get; set; }
}
Then you can use this model to get all the details by just passing the response in the web API:
ProductRepository ProdRepo = new ProductRepository();
public IHttpActionResult GetProduct()
{
var product = ProdRepo.GetProduct();
if (!product.Status)
{
return NotFound();
}
return Ok(product);
}
0 Comment(s)