IEnumerable<Price> IMarketPriceRepository.FetchPrices(IEnumerable<Item> items, SolarSystem system) { string urlData = ""; foreach (Item item in items) { urlData += "typeid=" + item.ApiId + "&"; } urlData += "usesystem=" + system.ApiId; XDocument doc = XDocument.Load(String.Format(String.Format(_priceURL, urlData))); IEnumerable<XElement> itemElements = doc.Element("evec_api").Element("marketstat").Elements("type"); IList<Price> prices = new List<Price>(); foreach (XElement itemElement in itemElements) { string itemApi = itemElement.Attribute("id").Value; Item currentItem = items.Single(i => i.ApiId.Equals(itemApi)); Price price = new Price { Item = currentItem, SolarSystem = system, Buy = Double.Parse(itemElement.Element("buy").Element("max").Value, CultureInfo.InvariantCulture), Sell = Double.Parse(itemElement.Element("sell").Element("min").Value, CultureInfo.InvariantCulture), Date = DateTime.Today }; prices.Add(price); } return prices.AsEnumerable(); }
Price IMarketPriceRepository.FetchPrice(Item item, SolarSystem system) { string urlData = String.Format("typeid={0}&usesystem={1}", item.ApiId, system.ApiId); XDocument doc = XDocument.Load(String.Format(_priceURL, urlData)); XElement itemElement = doc.Element("evec_api").Element("marketstat").Elements("type").First(); Price price = new Price { Item = item, SolarSystem = system, Buy = Double.Parse(itemElement.Element("buy").Element("max").Value, CultureInfo.InvariantCulture), Sell = Double.Parse(itemElement.Element("sell").Element("min").Value, CultureInfo.InvariantCulture), Date = DateTime.Today }; return price; }
public void UpdatePrice(Price price, string PriceMode) { int id = Int32.Parse(price.Item.ApiId); customPrice customPrice = this.CustomPrices.SingleOrDefault(cp => cp.typeID == id); if (customPrice == null) { customPrice = new customPrice(); customPrice.typeID = Int32.Parse(price.Item.ApiId); customPrice.price = price.GetPrice(PriceMode); customPrice.priceDate = price.Date; this.CustomPrices.Add(customPrice); } else { customPrice.price = price.GetPrice(PriceMode); customPrice.priceDate = price.Date; } }