Created
August 12, 2014 13:57
-
-
Save AlexArchive/e940cefe5f3c32bcf148 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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