title: How to pass model to WebApi controller?
body: <p>I am in need to write WebApi controllers. The task is to migrate from exisitng normal mvc controller to WebApi controllers.</p>
  
  <p>In this projects, almost all the beauty of the programming is used like:-</p>
  
  <ul>
  <li>Design Patterns - Repository + UOW, Factory + nUnit</li>
  <li>Dependency Injection</li>
  <li>SOLID </li>
  </ul>
  
  <p>This is my model in the <code>MyApp.Domain</code> layer</p>
  
  <pre><code>public class Customer
  {
     //please note that we are using Repository pattern &amp; so no Data Annotations like Required, Key are not used here. 
     public int CustomerID { get; set;}
  
     public string CustomerName { get; set;}
  
     public string EmailAddress { get; set;}
     // &amp; so on
  }
  </code></pre>
  
  <p>In the <code>MyApp.UI</code> layer, exists ViewModel for validation &amp; then passing the model to Service layer that. So this is how my MVC controllers looks like</p>
  
  <pre><code>  public class CustomerVM
    {
       [Required]
       public int CustomerID { get; set;}  // &amp; so on the other properties.
  
    }
  
  
    public ActionResult Registration(Customer VM)
    {
           if(Modelstate.IsValid)
           {
              //call service layer 
           }
           else
           {
  
           }
    }
  </code></pre>
  
  <p>Now my immediate task is to migrate this controller to WebApi controller.
  Henceforth, I created a separate project as <code>MyApp.WebApi</code></p>
  
  <p>Now my doubt is how should I pass the model to this WebApi controller.</p>
  
  <p>I am thinking to detach the ViewModel from UI layer to separate
  project as <code>MyApp.ViewModels</code> and put all the viewmodels in this layer
  &amp; reference the dll in UI layer &amp; WebApi layer.</p>
  
  <pre><code> public string POST([FromBody]CustomerVM customer)
   {
      if(Modelstate.IsValid)
      {
          //call the other service layer which will take care of DB handling
         return "Success";
      }
      else
      {
         return "Error";
      }   
   }
  </code></pre>
  
  <p>Is this the right way to do &amp; any other right way to do this??</p>