public void GetTitleWithPrice(double price) { _libRepo = new LibraryIndexRepo(); OpenXML(); // Find the title of the books that are greater then inserted price strExpression = $"/Library/User[//Price>{price}]"; // Select the node and place the results in an iterator. NodeIter = nav.Select(strExpression); if (NodeIter.Count != 0) { Console.WriteLine("Books that cost more than: " + price); //Iterate through the results showing the element value. while (NodeIter.MoveNext()) { Console.WriteLine(NodeIter.Current.OuterXml); } ; } else { Console.WriteLine("Error, Not Found: Please search for values between 0 - 2599."); } // Pause Console.ReadLine(); }
public void AveragePriceOfBooks(string name) { _libRepo = new LibraryIndexRepo(); OpenXML(); // Find the average cost of a book. // This expression uses standard XPath syntax. strExpression = $"sum(/Library/User/BooksRented[../Name = '{name}']/Price) " + $"div count(/Library/User/BooksRented[../Name = '{name}']/Price)"; double total = (double)nav.Evaluate(strExpression); // Use the Evaluate method to return the evaluated expression. Console.WriteLine($"The average price of the books for user {name} is {string.Format("{0:0.00}", total)}"); // Pause Console.ReadLine(); }