public void LoadPizzas() { string pizzasUrl = "http://coding-challenge.renderedtext.com/"; JSONPizzasModel jsonPizzasModel = LargeJSON.JSONmanipulator._download_serialized_json_data <JSONPizzasModel>(pizzasUrl); pizzas = RenderedPizza.Helpers.PizzasRepacker.RepackPizzas(jsonPizzasModel); PizzasWithMeat = PizzasRepacker.getPizzasWithMeat(pizzas); OnPropertyChanged("PizzasWithMeat"); PizzasWithMultipleChease = PizzasRepacker.getPizzasWithMultipleChease(pizzas); OnPropertyChanged("PizzasWithMultipleChease"); PizzasWithMeatAndOlives = PizzasRepacker.getPizzasWithMeatAndOlives(PizzasWithMeat); OnPropertyChanged("PizzasWithMeatAndOlives"); PizzasWithMozzarelaAndMushrooms = PizzasRepacker.getPizzasWithMozzarelaAndMushrooms(pizzas); OnPropertyChanged("PizzasWithMozzarelaAndMushrooms"); CalculatePercentages(); FindCheapestPizzas(); PrintJSONinFile(); }
public static ObservableCollection <PizzaModel> RepackPizzas(JSONPizzasModel jsonPizzasModel) { ObservableCollection <PizzaModel> tempPizzaModels = new ObservableCollection <PizzaModel>(); foreach (Pizza pizza in jsonPizzasModel.pizzas) { if (pizza.nil != null) { continue; } PizzaModel tempPizza = new PizzaModel(); tempPizza.PizzaName = pizza.name; tempPizza.Price = pizza.price; object pizzaType = pizza.GetType().GetProperty(tempPizza.PizzaName).GetValue(pizza, null); object pizzaIngredients = pizzaType.GetType().GetProperty("ingredients").GetValue(pizzaType, null); tempPizza.Ingredients = (string[])pizzaIngredients; tempPizzaModels.Add(tempPizza); } return(tempPizzaModels); }