title: Getting a single ID from loop using LINQ
body: <p>I have a method that groups items with the same productID together and then adds their quantity together for items in the shopping cart. Now I am trying to add to it where it also adds the quantity from a page that adds to the cart. So in a call to this method I send the productid and quantity selected by the user to add to the total quantity. But the problem I run into is comparing the productids of the items being sent to this method and the ones being grouped together.</p>
  
  <p>Here is what I have below, the commented parts is what I attempted to do to fix this but found out my thoughts were wrong on it.</p>
  
  <pre><code>double totalQty = 0;
  bool isQtyValid = true;
  
  List&lt;ShoppingCartDTO&gt; shoppingList = ShoppingCart.Fetch(string.Format("WHERE SessionID='{0}'", sessionID)); 
  foreach (ShoppingCartDTO temp in shoppingList)
   {
      var groupList = shoppingList.GroupBy(item =&gt; item.ProductID);
      foreach (var m in groupList)
       {                    
          //var productID = m.Select(p =&gt; p.ProductID);
          //int prodID = Convert.ToInt32(productID);
          //if (ProductID == prodID)
          //{
               var sum = m.Sum(i =&gt; i.Quantity);
               totalQty = sum;
               //totalQty += qty;
               isQtyValid = CheckQty(totalQty, temp.ProductID, temp.CustomerID);
          //}
       }
   }
  </code></pre>
  
  <p>If anyone can provide some pointers or ideas I would really appreciate it. If it could use more explaining I can do that as well, or if you would like to see more code that I am using I can add that too.</p>
  
  <p>Thank you to anyone that can help.</p>