Rohan Laghate

Rohan Laghate

  • NA
  • 79
  • 8.1k

Saving data in database using View Model

Mar 27 2017 1:19 PM
Hi,
 
Consider a scenario wherein I have 2 domain models say Customers and Orders and then there is a View Model CustomerOrderViewModel.
 
Now, I have a CreateOrder() method that accepts CustomerOrderViewModel as input parameter.
 
 
eg:-
 
   [HttpPost]
   public ActionResult CreateOrder(CustomerOrderViewModel input) 
{
      //code to save 
};
 Question:-  How do I save the data to these 2 domain entities from the view model? ie. the input parameter above will have the data of customers as well as orders however, I want to save the data related to Customers in the customers table where as the data related to Orders in orders table. How can I achieve this?
 
Thanks!
 

Answers (3)