public async Task <IActionResult> OutstandingInvoices() { var token = await _tokenStore.GetAccessTokenAsync(User.XeroUserId()); var connections = await _xeroClient.GetConnectionsAsync(token); if (!connections.Any()) { return(RedirectToAction("NoTenants")); } var data = new Dictionary <string, int>(); foreach (var connection in connections) { var accessToken = token.AccessToken; var tenantId = connection.TenantId.ToString(); var organisations = await _accountingApi.GetOrganisationsAsync(accessToken, tenantId); var organisationName = organisations._Organisations[0].Name; var outstandingInvoices = await _accountingApi.GetInvoicesAsync(accessToken, tenantId, statuses : "AUTHORISED", where : "Type == \"ACCREC\""); data[organisationName] = outstandingInvoices._Invoices.Count; } var model = new OutstandingInvoicesViewModel { Name = $"{User.FindFirstValue(ClaimTypes.GivenName)} {User.FindFirstValue(ClaimTypes.Surname)}", Data = data }; return(View(model)); }
public async Task <IActionResult> OutstandingInvoices() { var token = await _tokenStore.GetAccessTokenAsync(User.XeroUserId()); var connections = await _xeroClient.GetConnectionsAsync(token); if (!connections.Any()) { return(RedirectToAction("NoTenants")); } var data = new Dictionary <string, int>(); foreach (var connection in connections) { //Console.WriteLine("Connection ID :"+connection.id); var accessToken = token.AccessToken; var refreshToken = token.RefreshToken; var tenantId = connection.TenantId.ToString(); var organisations = await _accountingApi.GetOrganisationsAsync(accessToken, tenantId); var accounts = await _accountingApi.GetAccountsAsync(accessToken, tenantId); for (int i = 0; i < organisations._Organisations.Count(); i++) { await ImportContactDetails(accessToken, tenantId); await FetchInvoicesFromDb(accessToken, tenantId); } }/* * for(int i = 0; i < organisations._Organisations.Count(); i++) * { * Console.WriteLine("\nOrganisation #"+i+" is "+organisations._Organisations[i].Name); * Console.WriteLine("\nImport for this organisation ? Press Y to confirm or any other button to continue.."); * char input = Console.ReadKey().KeyChar; * if(input.ToString().ToUpper() == "Y" ) * { * await ImportContactDetails(accessToken, tenantId); * await FetchInvoicesFromDb(accessToken, tenantId); * goto Foo; * } * } * } * Foo:*/ var model = new OutstandingInvoicesViewModel { Name = $"{User.FindFirstValue(ClaimTypes.GivenName)} {User.FindFirstValue(ClaimTypes.Surname)}", Data = data }; return(View(model)); }