private async Task GetCustomerDataAsync() { _groups.Clear(); StorageFile customerDataJsonFile = await _roamingFolder.CreateFileAsync(string.Format("{0}.json", "Customers"), CreationCollisionOption.OpenIfExists); string jsonText = await FileIO.ReadTextAsync(customerDataJsonFile); if (string.IsNullOrWhiteSpace(jsonText)) return; JsonArray jsonArray = JsonArray.Parse(jsonText); var customerGroup = new CustomerDataGroup("Customer Default", "Customers", "Customer SubTitle", "image", "Customer Description"); Groups.Add(customerGroup); foreach (JsonValue groupValue in jsonArray) { JsonObject groupObject = groupValue.GetObject(); var itemObject = new CustomerDataItem(groupObject["Id"].GetString(), groupObject["Name"].GetString(), groupObject["Address"].GetString(), groupObject["PictureUrl"].GetString(), (Decimal) groupObject["Balance"].GetNumber()); customerGroup.Items.Add(itemObject); } }
private async Task GetCustomerDataAsync() { _groups.Clear(); StorageFile customerDataJsonFile = await _roamingFolder.CreateFileAsync(string.Format("{0}.json", "Customers"), CreationCollisionOption.OpenIfExists); string jsonText = await FileIO.ReadTextAsync(customerDataJsonFile); if (string.IsNullOrWhiteSpace(jsonText)) { return; } JsonArray jsonArray = JsonArray.Parse(jsonText); var customerGroup = new CustomerDataGroup("Customer Default", "Customers", "Customer SubTitle", "image", "Customer Description"); Groups.Add(customerGroup); foreach (JsonValue groupValue in jsonArray) { JsonObject groupObject = groupValue.GetObject(); var itemObject = new CustomerDataItem(groupObject["Id"].GetString(), groupObject["Name"].GetString(), groupObject["Address"].GetString(), groupObject["PictureUrl"].GetString(), (Decimal)groupObject["Balance"].GetNumber()); customerGroup.Items.Add(itemObject); } }
private async void LoadCustomers() { try { CustomerDataGroup firstGroup = _customerDataGroups.FirstOrDefault(); if (firstGroup == null) { firstGroup = new CustomerDataGroup("Customer Default", "Customers", "Customer SubTitle", "image", "Customer Description"); _customerDataGroups.Add(firstGroup); } // TODO: Create an appropriate data model for your problem domain to replace the sample data ObservableCollection<CustomerDataGroup> customerDataGroups = await CustomerDataSource.GetGroupsAsync(); if (!customerDataGroups.Any()) return; foreach (CustomerDataItem item in customerDataGroups.First().Items) { firstGroup.Items.Add(item); } } catch (Exception ex) { Debug.WriteLine(ex); } }