Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to map View Model back to Domain Model in a POST action?
    primarykey
    data
    text
    <p>Every article found in the Internet on using ViewModels and utilizing Automapper gives the guidelines of the "Controller -> View" direction mapping. You take a domain model along with all Select Lists into one specialized ViewModel and pass it to the view. That's clear and fine.<br> The view has a form, and eventually we are in the POST action. Here all the Model Binders come to the scene along with <em>[obviously] another</em> View Model which is <em>[obviously] related</em> to the original ViewModel at least in the part of naming conventions for the sake of binding and validation.</p> <p><strong>How do you map it to your Domain Model?</strong></p> <p>Let it be an insert action, we could use the same Automapper. But what if it was an update action? We have to retrieve our Domain Entity from the Repository, update it's properties according to the values in the ViewModel and save to the Repository.</p> <p><strong>ADDENDUM 1 (9th of February 2010):</strong> Sometimes, assigning Model's properties is not enough. There should be taken some action against Domain Model according to the values of View Model. I.e., some methods should be called on Domain Model. Probably, there should be a kind of an Application Service layer which stands between Controller and Domain in order to process View Models...</p> <hr> <p><strong>How to organize this code and where to place it to achieve the following goals?</strong></p> <ul> <li>keep controllers thin</li> <li>honor SoC practice</li> <li>follow Domain-Driven Design principles</li> <li>be DRY</li> <li>to be continued ...</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload