public class Order
{
public decimal Id { get; set; }
public decimal customerId { get; set; }
public string payment_method { get; set; }
public string payment_status { get; set; }
public double total_price { get; set; }
public string date { get; set; }
public List<OrderDetail> OrderDetails { get; set; }
public List<Address> OrderAddresses { get; set; }
}
public class OrderDetail
{
public decimal product_id { get; set; }
public string product_name { get; set; }
public double price { get; set; }
public double quantity { get; set; }
}
public class Address
{
public string type { get; set; }
public string address { get; set; }
public string city { get; set; }
public string state_province { get; set; }
public string postal_code { get; set; }
public string country { get; set; }
public string telephone { get; set; }
public string fax { get; set; }
}
here is my model some of my API. using whole model like orderAdd
, orderDetail
. But, for order listing I want few fields from Order
Model e.g
Id
, total_price
, date
and exclude rest of the fields and list in Web API response.
below is my response code
[ResponseType(typeof(List<Order>))]
[HttpGet, Route("api/Orders/getOrderList")]
public IHttpActionResult getOrderLists(decimal customerId, int limit = 3)
{
List<Order> Model = new List<Order>();
var orders = db.OrderMasters.Where(p => p.CustomerId == customerId).Take(limit);
foreach (var o in orders)
{
Order O = new Order();
O.Id = o.OrderId;
O.date = o.PurchasedOn;
O.total_price = o.Total;
Model.Add(O);
}
return Ok(Model);
}