I have a website and when you order 2 products they are added in the database so know i have this model
public IQueryable<CommonLayer.Models.OrdersModel> GetOrderAsModel(Guid id)
{
return (from p
in this.Entities.ORDERS
join orderdetails in this.Entities.ORDERDETAILS on p.OrderId equals orderdetails.OrderDetailsOrderId
where p.OrderId == id
select new CommonLayer.Models.OrdersModel()
{
Orderid = p.OrderId,
Orderdetailsid = orderdetails.OrderDetailsOrderId,
OrderDate = p.OrderDate,
Orderstatus = p.OrderStatus,
ProductQty = orderdetails.ProductQuantity,
OrderNum = p.OrderNum,
Userid = p.UserId,
ProductName = orderdetails.PRODUCT.ProductName
});
}
This model return the order along with the order details(if for example i have two products i have two orderdetails)
Now i am trying to add the ability to alter the value of some fields from an order and i am trying to get all products in a specific order, if i have for example 4 products it returns for but they are all exactly like the first product entered even if i have different products, even the quantity if in the order i have 1 of one product and 5 of the other it returns two products same name same quantity. Below code shows the for each i am trying to implement:
@foreach (var item in Model)
{
<div class="form-group">
@Html.LabelFor(model => model.FirstOrDefault().ProductName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FirstOrDefault().ProductName, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FirstOrDefault().ProductQty, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FirstOrDefault().ProductQty, new { htmlAttributes = new { @class = "form-control" }})
</div>
</div>
}