public void InsertTenant(TenantSQLite tenant) { lock (locker) { database.Insert(tenant); } }
public static async Task <bool> GetTenantID() { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Preferences.Get("AccessToken", string.Empty)); HttpResponseMessage response = await client.GetAsync(@"https://api.xero.com/connections"); if (!response.IsSuccessStatusCode) { return(false); } string responseBody = await response.Content.ReadAsStringAsync(); var tenant = JsonConvert.DeserializeObject <List <Tenant> >(responseBody); string tenantId = Preferences.Get("TenantID", string.Empty); bool isExist = false; foreach (Tenant t in tenant) { if (tenantId == t.tenantId) { isExist = true; } } if (!isExist) { Preferences.Set("TenantID", tenant[0].tenantId); } App.TenantDatabase.DeleteAllTenants(); for (int i = 0; i < tenant.Count; i++) { TenantSQLite tenantSQLite = new TenantSQLite(); tenantSQLite.TenantID = tenant[i].tenantId; tenantSQLite.TenantName = tenant[i].tenantName; tenantSQLite.TenantIndex = i; App.TenantDatabase.InsertTenant(tenantSQLite); } return(true); }