public async void LoadData() { CompanyBranchResponse companyBranchResponse = await CompanyBranches.getList(); List <CompanyBranch> items = companyBranchResponse.Items; lstItems.ItemsSource = items; }
public static async Task <CompanyBranchResponse> getList(string filtro = "", string ordenar_por = "", string orden = "", string sucursal = "0") { CompanyBranchResponse response = new CompanyBranchResponse(); try { List <CloureParam> cparams = new List <CloureParam>(); cparams.Add(new CloureParam("module", "company_branches")); cparams.Add(new CloureParam("topic", "listar")); if (ordenar_por.Length > 0) { cparams.Add(new CloureParam("ordenar_por", ordenar_por)); } if (orden.Length > 0) { cparams.Add(new CloureParam("orden", orden)); } string res = await CloureManager.ExecuteAsync(cparams); JsonObject api_result = JsonObject.Parse(res); string error = api_result.GetNamedString("Error"); if (error == "") { JsonObject api_response = api_result.GetNamedObject("Response"); JsonArray registers = api_response.GetNamedArray("Registros"); foreach (JsonValue jsonValue in registers) { JsonObject register = jsonValue.GetObject(); CompanyBranch companyBranch = new CompanyBranch(); companyBranch.Id = CloureManager.ParseInt(register.GetNamedValue("Id")); companyBranch.Name = register.GetNamedString("Nombre"); JsonArray available_commands_arr = register.GetNamedArray("AvailableCommands"); companyBranch.AvailableCommands = new List <AvailableCommand>(); foreach (JsonValue available_cmd_obj in available_commands_arr) { JsonObject available_cmd_item = available_cmd_obj.GetObject(); int available_cmd_id = (int)available_cmd_item.GetNamedNumber("Id"); string available_cmd_name = available_cmd_item.GetNamedString("Name"); string available_cmd_title = available_cmd_item.GetNamedString("Title"); AvailableCommand availableCommand = new AvailableCommand(available_cmd_id, available_cmd_name, available_cmd_title); companyBranch.AvailableCommands.Add(availableCommand); } response.Items.Add(companyBranch); } } else { throw new Exception(error); } } catch (Exception ex) { var dialog = new MessageDialog(ex.Message); await dialog.ShowAsync(); } return(response); }