ASP.NET MVC 2: Mechanics behind the order / order line in the edit form

In this question, I am looking for links / code for processing IList<OrderLine>in the form of editing MVC 2. In particular, I am interested in sending a full order to the client, and then the edited order is sent back to the object (for saving) using:

Html.EditorFor (m => m .orderlines [i]) (where the line order is an enumerated object)

Editing an order having several order lines (two tables, order and order, one for many) seems to be complicated. Are there any links / examples / templates to tell how to create this form that edits the entity and related objects in one form (in C # MVC 2)?

IList really throws me for a loop. Should I have it there (having another form for editing one order)? How could you use the server side of the factory to create an empty OrderLine in the form without sending the entire form back to the server? I hope that we will not process individual order lines with separate save, delete, etc. buttons. (For example, they can open an order, delete all rows, and then cancel, which should not have changed the order in either the repository or the database.

Class examples:

public class ViewModel {
    public Order            order       {get;set;}  // Only one order
}

public class Order {
    public int              ID          {get;set;} // Order Identity
    public string           name        {get;set;}
    public IList<OrderLine> orderlines  {get;set;} // Order has multiple lines
}

public class OrderLine {
    public int              orderID     {get;set;} // references Order ID above
    public int              orderLineID {get;set;} // Order Line identity (need?)
    public Product          refProduct  {get;set;} // Product value object
    public int              quantity    {get;set;} // How many we want
    public double           price       {get;set;} // Current sale price
}
+3
source share

Source: https://habr.com/ru/post/1746913/


All Articles