public void SetOnlineDocumentsToLocal() { WebMethods webapi = new WebMethods(); webapi.GetPolicies(); webapi.policysEvent += ((WebMethods webAPISender, EventArgs e2) => { Device.BeginInvokeOnMainThread(() => { PolicyModel.DocType[] PolicyDocTypes = SimpleJson.DeserializeObject <PolicyModel.DocType[]>(webAPISender.Polocysresponse); List <Policies> OfflineList = new List <Policies>(); foreach (PolicyModel.DocType dst in PolicyDocTypes) { DataItems = new ObservableCollection <DocumentItem>(); int i = 0; PolicySubTypes = new string[5]; foreach (PolicyModel.DocSubType pd in dst.DocSubTypes) { PolicySubTypes[i] = pd.Name.ToString(); DocumentType dt3 = new DocumentType { DocumentTypeId = i, DocumentTypeTitle = pd.Name.ToString() }; int j = 0; foreach (PolicyModel.Document orgDoc in pd.Documents) { DocumentItem pdi = new DocumentItem(); pdi.DocumentItemId = j; pdi.DocumentItemTitle = orgDoc.DocumentName; pdi.DocumentType = dt3; DataItems.Add(pdi); Policies OfflineSingleP = new Policies(); OfflineSingleP.DocName = orgDoc.DocumentName; OfflineList.Add(OfflineSingleP); OfflineSingleP = null; j = j + 1; } i = i + 1; } } //PoliciesRepository pr = new PoliciesRepository(); //pr.AddAllPolicies(OfflineList); }); }); }
private void GetOnlineDocuments() { WebMethods webapi = new WebMethods(); if (DataItems != null) { SetDocumentDetails(); } else { webapi.GetPolicies(); } webapi.policysEvent += ((WebMethods webAPISender, EventArgs e2) => { Device.BeginInvokeOnMainThread(() => { PolicyModel.DocType[] PolicyDocTypes = SimpleJson.DeserializeObject <PolicyModel.DocType[]>(webAPISender.Polocysresponse); List <Policies> OfflineList = new List <Policies>(); foreach (PolicyModel.DocType dst in PolicyDocTypes) { DataItems = new ObservableCollection <DocumentItem>(); int i = 0; PolicySubTypes = new string[5]; foreach (PolicyModel.DocSubType pd in dst.DocSubTypes) { PolicySubTypes[i] = pd.Name.ToString(); DocumentType dt3 = new DocumentType { DocumentTypeId = i, DocumentTypeTitle = pd.Name.ToString() }; int j = 0; foreach (PolicyModel.Document orgDoc in pd.Documents) { //await App.PersonRepo.AddNewPersonAsync(orgDoc.DocumentName); DocumentItem pdi = new DocumentItem(); pdi.DocumentItemId = j; pdi.DocumentItemTitle = orgDoc.DocumentName; pdi.DocumentType = dt3; DataItems.Add(pdi); //from here Policies OfflineSingleP = new Policies(); OfflineSingleP.DocName = orgDoc.DocumentName; OfflineList.Add(OfflineSingleP); OfflineSingleP = null; //till here j = j + 1; } i = i + 1; } //DocumentTypes = new ObservableCollection<Grouping<SelectDocumentTypeViewModel, DocumentItem>>(); if (DataItems != null) { SetDocumentDetails(); } } }); }); }