I'd like to exchange/share some design patterns that a programmer can apply when designing screen views which formerly enable adding and editing records to a DB for entities which have a foreign key.
From my experience I have 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 requires the programmer to code many action method and views which can be engineered a little bit better than 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.