It would be nice to share some design patterns that a programmer can apply when designing views which formerly enable adding and editing records to a database for entities wich have foreign keys.
By looking at my experience I have very often applied a couple of methods:
- The user add the child record by selecting Add Child from the Parent View
- The user add the child record by selecting the parent relation directly in the create/edit page
In the first case the pattern is really easy. Suppose you have Customer and Store entities where a customer can have many stores. The programmer could then add a button "Add Store" in the customer detail page which will invoke a GET action on the server that returns a default populated Store with a Customer already set. For example:
[HttpGet]
public ActionResult CreateStore( int customerID ) {
return View( new StoreViewModel() { CustomerID = customerID } );
}
[HttpPost]
public ActionResult SaveStore( StoreViewModel store ) {
[...save store here...]
}
Although this is very easy to implement it needs that the programmer will code many and many actions method and views wich of course can be engineered a little bit better than in this example.
I would like to know if there is any other pattern that you use in your experience. Also if there is any link/book to read to further explore this topic.
Aucun commentaire:
Enregistrer un commentaire