title: How to read all textbox values(Map to database fileds) and store them in Database in WPF - MVVM
body: <p>I am new to WPF and MVVM. After a long invention i got to know how to retrieve data from database and bind it to a itemcontrol/listview/gridview.</p>
  
  <p>But my problem i am not getting how to read bunch of textbox values and store as a  new record in database.</p>
  
  <p>Here is my sample code..</p>
  
  <p>View</p>
  
  <pre><code>&lt;ItemsControl ItemsSource="{Binding AllEmployees}"&gt;
              &lt;ItemsControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal"&gt;
                          &lt;TextBox Width="100" Text="{Binding FirstName}" Margin="4"/&gt;
                          &lt;TextBox Width="100" Text="{Binding LastName}" Margin="4"/&gt;
                          &lt;TextBox Width="100" Text="{Binding Age}" Margin="4"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ItemsControl.ItemTemplate&gt;
  &lt;/ItemsControl&gt;
  &lt;!-- For new Employee Details --&gt;
  &lt;StackPanel&gt;
          &lt;TextBox x:Name="FirstName"/&gt;
          &lt;TextBox x:Name="LastName"/&gt;
          &lt;TextBox x:Name="Age"/&gt;
          &lt;Button Content="New" Command="{Binding NewEmployeeCommand}"/&gt;
   &lt;/StackPanel&gt;
  </code></pre>
  
  <p>My cs file is</p>
  
  <pre><code>    public ObservableCollection&lt;DataAccess.Employee&gt; AllEmployees
              {
                  get;
                  private set;
              }  
  
      public EmployeeListViewModel(EmployeeRepository employeeRepository)
              {
                  if (employeeRepository == null)
                  {
                      throw new ArgumentNullException("employeeRepository");
                  }
  
                  _employeeRepository = employeeRepository;
                  this.AllEmployees = new ObservableCollection&lt;DataAccess.Employee&gt; 
                                      (_employeeRepository.ListAll());
   }  
  </code></pre>
  
  <p>Now how could i store a new employee Firstname, Lastname, Age in database by reading those text boxes..</p>
  
  <p>How to write function for <strong>NewEmployeeCommand</strong> event to read the textboxes( <strong>mapping of textboxes to appropriate datafileds in database</strong>) and store the data in database.</p>
  
  <p>Thanks a Lot !</p>