public SampleDataItem(String uniqueId, String title, String subtitle, String imagePath, String description, String content, double preparationTime, double rating, bool favorite, string tileImagePath, ObservableCollection<string> ingredients, SampleDataGroup group) { this.UniqueId = uniqueId; this.Title = title; this.Subtitle = subtitle; this.Description = description; this.ImagePath = imagePath; this.Content = content; this.PreparationTime = preparationTime; this.Rating = rating; this.Favorite = favorite; this.TileImagePath = tileImagePath; this.Ingredients = ingredients; this.Group = group; }
public static async Task<SampleDataGroup> GetTopRatedRecipesAsync(int count) { await _sampleDataSource.GetSampleDataAsync(); var favorites = new SampleDataGroup("TopRated", "Top Rated", "Top Rated Recipes", "", "Favorite recipes rated by our users.", "", ""); var topRatedRecipes = _sampleDataSource.Groups.SelectMany(group => group.Items).OrderByDescending(recipe => recipe.Rating).Take(count); foreach (var recipe in topRatedRecipes) { favorites.Items.Add(recipe); } return favorites; }
public static IEnumerable<SampleDataGroup> Search(string searchText, bool titleOnly = false) { var query = searchText.ToUpperInvariant(); _sampleDataSource.GetSampleDataAsync().Wait(); return _sampleDataSource.Groups .Select(group => { var filteredGroup = new SampleDataGroup(group.UniqueId, group.Title, group.Subtitle, group.ImagePath, group.Description, group.GroupImagePath, group.GroupHeaderImagePath); // add recipes that contain search text in title or content foreach (var item in group.Items .Where(item => item.Title.ToUpperInvariant().Contains(query) || (!titleOnly && item.Content.ToUpperInvariant().Contains(query)))) { filteredGroup.Items.Add(item); } return filteredGroup; }); }
private async Task GetSampleDataAsync() { if (this._groups.Count != 0) return; Uri dataUri = new Uri("ms-appx:///DataModel/SampleData.json"); StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri); string jsonText = await FileIO.ReadTextAsync(file); JsonObject jsonObject = JsonObject.Parse(jsonText); JsonArray jsonArray = jsonObject["Groups"].GetArray(); foreach (JsonValue groupValue in jsonArray) { JsonObject groupObject = groupValue.GetObject(); SampleDataGroup group = new SampleDataGroup(groupObject["UniqueId"].GetString(), groupObject["Title"].GetString(), groupObject["Subtitle"].GetString(), groupObject["ImagePath"].GetString(), groupObject["Description"].GetString(), groupObject[ "GroupImagePath" ].GetString(), groupObject[ "GroupHeaderImagePath" ].GetString()); foreach (JsonValue itemValue in groupObject["Items"].GetArray()) { JsonObject itemObject = itemValue.GetObject(); group.Items.Add(new SampleDataItem(itemObject["UniqueId"].GetString(), itemObject["Title"].GetString(), itemObject["Subtitle"].GetString(), itemObject["ImagePath"].GetString(), itemObject["Description"].GetString(), itemObject["Content"].GetString(), itemObject["PreparationTime"].GetNumber(), itemObject["Rating"].GetNumber(), itemObject["Favorite"].GetBoolean(), itemObject["TileImagePath"].GetString(), new ObservableCollection<string>(itemObject["Ingredients"].GetArray().Select(p => p.GetString())),group)); } this.Groups.Add(group); } }