title: Show start and end time for each User ID respectively
body: <p>I am running a <code>foreach</code> loop on each <code>UserId</code> but for some reason... In my <code>xml</code>, only one <code>userId</code> is being displayed along with all the start time and end time for all <code>userIds</code>. I need it to show <code>start</code> and <code>end</code> time for each <code>userId</code> respectively.</p>
  
  <p>So it looks like this:</p>
  
  <pre><code>User2
  Start
  End
  Start
  End
  Start
  End
  </code></pre>
  
  <p>It needs to looks like this:</p>
  
  <pre><code>User1
  Start
  End
  Start
  End
  
  User2
  Start
  End
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>foreach (String userId in request.Users) // request.Users is a Array of UserId's 
  {
      List&lt;UserModel&gt; result = // I am making my DataAccess Layer call here.
      UserRecord record = new UserRecord();
      record.UserId = userId;
      record.TimePeriodList = new List&lt;TimePeriod&gt;();
      for (int i = 0; i &lt; result.Count; i += 2)
      {
          TimePeriod timeData = new TimePeriod();
          timeData.StartTime = result[i].TimeDate;
          // if result count is an odd number and this is the last iteration for the UserId
          if (((result.Count &amp; 1) == 1) &amp;&amp; (i == result.Count))
              {
                  timeData.EndTime = result[i + 1].TimeDate;
              }
              record.TimePeriodList.Add(timeData);
          }
          response.UserRecordList = new List&lt;UserRecord&gt;();
          response.UserRecordList.Add(record);
  }
  
  public class GetUserResponse
  {
      private List&lt;UserRecord&gt; userRecordList;
  
      public List&lt;UserRecord&gt; UserRecordList
      {
          get { return userRecordList; }
          set { userRecordList = value; }
      }
  }
  
  public class UserRecord
  {
      private string userId;
      private List&lt;TimePeriod&gt; timePeriodList;
  
      public string UserId
      {
          get { return userId; }
          set { userId = value; }
      }
  
      public List&lt;TimePeriod&gt; TimePeriodList
      {
          get { return timePeriodList; }
          set { timePeriodList = value; }
      }
  }
  
  public class TimePeriod
  {
      private DateTime startTime;
      private DateTime endTime;
  
      public DateTime StartTime
      {
          get { return startTime; }
          set { startTime = value; }
      }
  
      public DateTime EndTime
      {
          get { return endTime; }
          set { endTime = value; }
      }
  }
  </code></pre>
  
  <p>My data returned from <code>DataAccess</code> layer looks like this:</p>
  
  <pre><code>UserId    Time        EventType
  Test1   xx-xx-xxxx   Start
  Test1   xx-xx-xxxx   End
  Test2   xx-xx-xxxx   Start
  </code></pre>
  
  <p>So if there is an odd number then the End time for that <code>User</code> is <code>DateTime.MinValue</code> by default.</p>