title: Problems understanding use of MVVM when using WCF DTO's in a WPF smart client app
body: <p>Having very little experience in the area I am writing a WPF smart client app communicating to a WCF backend using MVVM and am really struggling to make the right decisions out of all the information out there. Which leads me to a set of questions that I hope can be resolved here by people more experienced in this area.</p>
  
  <p>As an example, one of of the screens will allow for entering an order and adding order lines to the order. </p>
  
  <p><strong>What is used as the model?</strong></p>
  
  <p>On the WCF service I have the following simplified DTO:</p>
  
  <pre><code>public OrderDTO
  {
     string orderDetails { get; set; }
     List&lt;OrderLineDTO&gt; OrderLines { get; set; }
  }
  
  public OrderLineDTO
  {
     int customerId { get; set; }
     int productId { get; set; }
     double quantity { get; set; }
  }
  </code></pre>
  
  <p>And a WCF service which has the following method:</p>
  
  <pre><code>public OrderService Order
  {
      CreateOrderResponse CreateOrder(OrderDTO order) 
  }
  </code></pre>
  
  <p>In my WPF smart client I then have a reference to the DTO but clearly it does not implement <code>INotifyPropertyChanged</code> as it is purely for transport. </p>
  
  <p><strong>Questions</strong></p>
  
  <p>Would the recommended approach be to convert these DTOs to a model that implements <code>INotifyPropertyChanged</code> using Automapper or similar? Or should the DTO be used as the model directly in the ViewModel? </p>
  
  <p><strong>Communicating between view models</strong></p>
  
  <p>Currently, I have an order view with 2 tabs (<code>Order</code> and <code>OrderLines</code>) with ViewModels <code>OrderViewModel</code> and <code>OrderLineViewModel</code>. On the order tab I have a <code>ComboBox</code> containing customer Ids and names. When I select a customer on the <code>OrderView</code>, I need to advise the <code>OrderLineView</code> that a customer has been selected so that the <code>ComboBox</code> only shows products belonging to that customer. </p>
  
  <p><strong>Questions</strong></p>
  
  <p>How would the <code>OrderViewModel</code> communicate to the <code>OrderLineViewModel</code> in this scenario?</p>
  
  <p><strong>Adding an order line and applying logic / business rules</strong></p>
  
  <p>As the server level application will be used by multiple clients e.g PCs, mobile devices.. I would like to ensure that all the business rules are applied in the server level application. As an example, when an order line is added. if it is of a certain product type it can only be added if the customer has a certain certification.</p>
  
  <p>However, everything I have read about MVVM states that the model is what applies business rules and behaviour - all these examples have implemented the model on the client side. Ideally, I do not want to duplicate the same checks on both the client and the server so I was wondering how one would go about ensuring that this does not happen. </p>
  
  <p><strong>Questions</strong> </p>
  
  <p>Do you allow the user to add an <strong><em>invalid</em></strong> line, send the request to the server, let the server apply the relevant rules and return the response? Or do you somehow apply the logic in the smart client app before sending the request to the server?</p>
  
  <p>I really want to get better in all the areas I have outlined here and I thank you in advance for any responses.</p>
  
  <p>Thanks</p>
  
  <p>Alex</p>
  
  <p><strong>Edit:</strong>
  Thanks everyone for your contribution as it has helped me become a little more clear in terms of the best way forward. All the answers were good but I have decided to accept Uri's answer as it fits best with my thoughts at this stage. However, I am still not sure of the best way to handle the conversion from an Id of the DTO to a SelectedItem in the ItemsSource which is a list of ViewModels. I can see that a Converter might work but I am going to try and find another solution. Thanks Alex</p>