/// <summary> /// Constructor /// </summary> /// <param name="model"></param> public LocationPriceModelView(LocationPriceViewModel model) { InitializeComponent(); Title = model.ShoppingListName; BindingContext = model; }
/// <summary> /// Method to compare prices for the given locations and put the results in the LocationPriceModels /// </summary> /// <param name="locations"></param> private void ComparePrices(IEnumerable <LocationModel> locations) { // Loop through the locations foreach (var location in locations) { try { // Create a new location price model for this location var lpm = new LocationPriceViewModel() { Location = location, ShoppingListName = shoppingList.Name }; // Loop through each iqp in the shopping list foreach (var item in shoppingList.Items) { // Get the best ipl match for the iqp var ipl = GetBestMatch(item, location); if (ipl == null) { break; } // Create an ItemMatch to be added to the LocationPriceViewModel var itemMatch = new ItemMatchViewModel() { Iqp = item, Matched = false, }; // Calculate price and set attributes if ipl match has been found if (ipl != null) { var price = CalculatePrice(item, ipl); lpm.Price += price; lpm.NumberOfItemsMatched++; itemMatch.Matched = true; itemMatch.Price = Math.Round(price, 2); itemMatch.MatchedTo = ipl.Name; itemMatch.ImageUrl = ipl.ImageUrl; } // Add the match item to the LocationPriceViewModel lpm.ItemMatches.Add(itemMatch); } // Round the price lpm.Price = Math.Round(lpm.Price, 2); // Add the LocationPriceViewModel to the collection if (lpm.NumberOfItemsMatched != 0) { locationPriceModels.Add(lpm); } // Remove the refreshing icon ShoppingListsView.IsRefreshing = false; } catch (Exception e) { App.Log.Error("ComparePrices", e.Message + "\n" + e.StackTrace); } } }