Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Created August 12, 2014 13:57
Show Gist options
  • Save AlexArchive/e940cefe5f3c32bcf148 to your computer and use it in GitHub Desktop.
Save AlexArchive/e940cefe5f3c32bcf148 to your computer and use it in GitHub Desktop.
case "1":
Console.WriteLine("Select which of the following to add to cart by entering it's number:");
foreach (var product in result)
{
Console.WriteLine(" {0}. {1}, Stock: {2}, Price: {3}", product.RecordNumber, product.Name, product.Stock, product.Price);
}
int ProductInput = Convert.ToInt32(Console.ReadLine());
// answer..
var selectedProduct = result.Single(product => product.RecordNumber == ProductInput);
ShoppingCart.AddProduct(selectedProduct);
var productElement =
(from descendant in XDoc.Descendants("product")
where descendant.Element("recordNumber").Value == ProductInput.ToString()
select descendant).Single();
var stock = Convert.ToInt32(productElement.Element("stock").Value);
productElement.Element("stock").Value = (stock - 1).ToString();
XDoc.Save("inventory.xml");
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment