// GET: /Organisation/ public async Task <ActionResult> Index() { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value, httpClientFactory); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); var AccountingApi = new AccountingApi(); var response = await AccountingApi.GetOrganisationsAsync(accessToken, xeroTenantId); var organisation_info = new Organisation(); organisation_info = response._Organisations[0]; return(View(organisation_info)); }
// GET: /InvoiceSync/ public async Task <ActionResult> Index() { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value, httpClientFactory); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); var AccountingApi = new AccountingApi(); var sevenDaysAgo = DateTime.Now.AddDays(-7).ToString("yyyy, MM, dd"); var invoicesFilter = "Date >= DateTime(" + sevenDaysAgo + ")"; var response = await AccountingApi.GetInvoicesAsync(accessToken, xeroTenantId, null, invoicesFilter); var invoices = response._Invoices; return(View(invoices)); }
public async Task <ActionResult> Create(string Name, string Number) { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); var asset = new Asset() { AssetName = Name, AssetNumber = Number }; var AssetApi = new AssetApi(); var response = await AssetApi.CreateAssetAsync(accessToken, xeroTenantId, asset); return(RedirectToAction("Index", "AssetsInfo")); }
public async Task <ActionResult> Create(string Name, string EmailAddress) { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value, httpClientFactory); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); var contact = new Contact(); contact.Name = Name; contact.EmailAddress = EmailAddress; var contacts = new Contacts(); contacts._Contacts = new List <Contact>() { contact }; var AccountingApi = new AccountingApi(); var response = await AccountingApi.CreateContactsAsync(accessToken, xeroTenantId, contacts); return(RedirectToAction("Index", "ContactsInfo")); }
// GET: ContactsInfo public async Task <ActionResult> Index() { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; var serviceProvider = new ServiceCollection().AddHttpClient().BuildServiceProvider(); var httpClientFactory = serviceProvider.GetService <IHttpClientFactory>(); XeroConfiguration XeroConfig = new XeroConfiguration { ClientId = ConfigurationManager.AppSettings["XeroClientId"], ClientSecret = ConfigurationManager.AppSettings["XeroClientSecret"], CallbackUri = new Uri(ConfigurationManager.AppSettings["XeroCallbackUri"]), Scope = ConfigurationManager.AppSettings["XeroScope"], State = ConfigurationManager.AppSettings["XeroState"] }; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig, httpClientFactory); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); var AccountingApi = new AccountingApi(); var response = await AccountingApi.GetContactsAsync(accessToken, xeroTenantId); var contacts = response._Contacts; return(View(contacts)); }
public async Task <ActionResult> Create(string Name, string LineDescription, string LineQuantity, string LineUnitAmount, string LineAccountCode) { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value, httpClientFactory); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); var contact = new Contact(); contact.Name = Name; var line = new LineItem() { Description = LineDescription, Quantity = decimal.Parse(LineQuantity), UnitAmount = decimal.Parse(LineUnitAmount), AccountCode = LineAccountCode }; var lines = new List <LineItem>() { line }; var invoice = new Invoice() { Type = Invoice.TypeEnum.ACCREC, Contact = contact, Date = DateTime.Today, DueDate = DateTime.Today.AddDays(30), LineItems = lines }; var invoiceList = new List <Invoice>(); invoiceList.Add(invoice); var invoices = new Invoices(); invoices._Invoices = invoiceList; var AccountingApi = new AccountingApi(); var response = await AccountingApi.CreateInvoicesAsync(accessToken, xeroTenantId, invoices); var updatedUTC = response._Invoices[0].UpdatedDateUTC; return(RedirectToAction("Index", "InvoiceSync")); }
public async Task <ActionResult> Create(string firstName, string lastName, string DateOfBirth) { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value, httpClientFactory); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); // var contact = new Contact(); // contact.Name = Name; // contact.EmailAddress = EmailAddress; // var contacts = new Contacts(); // contacts._Contacts = new List<Contact>() { contact }; DateTime dob = DateTime.Today.AddYears(-20); HomeAddress homeAddress = new HomeAddress() { AddressLine1 = "6 MeatMe Street", AddressLine2 = " ", Region = State.VIC, City = "Long Island", PostalCode = "9999", Country = "New York" }; Employee employee = new Employee() { FirstName = firstName, LastName = lastName, DateOfBirth = dob, HomeAddress = homeAddress }; var employees = new List <Employee>() { employee }; var PayrollAUApi = new PayrollAuApi(); var response = await PayrollAUApi.CreateEmployeeAsync(accessToken, xeroTenantId, employees); return(RedirectToAction("Index", "EmployeesInfo")); }
public async Task <ActionResult> Create(string Name, string EmailAddress) { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; var serviceProvider = new ServiceCollection().AddHttpClient().BuildServiceProvider(); var httpClientFactory = serviceProvider.GetService <IHttpClientFactory>(); XeroConfiguration XeroConfig = new XeroConfiguration { ClientId = ConfigurationManager.AppSettings["XeroClientId"], ClientSecret = ConfigurationManager.AppSettings["XeroClientSecret"], CallbackUri = new Uri(ConfigurationManager.AppSettings["XeroCallbackUri"]), Scope = ConfigurationManager.AppSettings["XeroScope"], State = ConfigurationManager.AppSettings["XeroState"] }; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig, httpClientFactory); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); var contact = new Contact { Name = Name, EmailAddress = EmailAddress }; var contacts = new Contacts(); contacts._Contacts = new List <Contact>() { contact }; var AccountingApi = new AccountingApi(); var response = await AccountingApi.CreateContactsAsync(accessToken, xeroTenantId, contacts); return(RedirectToAction("Index", "ContactsInfo")); }
// GET: /IdentityInfo/ public async Task <ActionResult> Index() { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value, httpClientFactory); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; var IdentityApi = new IdentityApi(); var response = await IdentityApi.GetConnectionsAsync(accessToken); var connections = response; return(View(connections)); }
// GET /Authorization/Disconnect public async Task <ActionResult> Disconnect() { var client = new XeroClient(XeroConfig.Value, httpClientFactory); var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; Tenant xeroTenant = xeroToken.Tenants[0]; await client.DeleteConnectionAsync(xeroToken, xeroTenant); TokenUtilities.DestroyToken(); return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult> Delete(string connectionId) { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value, httpClientFactory); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; Guid connectionIdGuid = Guid.Parse(connectionId); var IdentityApi = new IdentityApi(); await IdentityApi.DeleteConnectionAsync(accessToken, connectionIdGuid); TokenUtilities.DestroyToken(); return(RedirectToAction("Index", "Home")); }
// GET: /EmployeesInfo/ public async Task <ActionResult> Index() { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value, httpClientFactory); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); var PayrollAUApi = new PayrollAuApi(); var response = await PayrollAUApi.GetEmployeesAsync(accessToken, xeroTenantId); var employees = response._Employees; return(View(employees)); }
// GET: /InvoicePdf/ public async Task <ActionResult> Index() { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); Guid invoiceId = Guid.Parse("d5654fc7-be8e-42e5-802a-9f5ab9d2476a"); var AccountingApi = new AccountingApi(); var response = await AccountingApi.GetInvoiceAsPdfAsync(accessToken, xeroTenantId, invoiceId); return(new FileStreamResult(response, "application/pdf")); }
// GET: /Assets/ public async Task <ActionResult> Index() { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); var AssetApi = new AssetApi(); var response = await AssetApi.GetAssetsAsync(accessToken, xeroTenantId, AssetStatusQueryParam.DRAFT); var assetItems = response.Items; return(View(assetItems)); }
// GET: /InvoiceSync/ public async Task <ActionResult> Index() { var xeroToken = TokenUtilities.GetStoredToken(); var utcTimeNow = DateTime.UtcNow; if (utcTimeNow > xeroToken.ExpiresAtUtc) { var client = new XeroClient(XeroConfig.Value); xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken); TokenUtilities.StoreToken(xeroToken); } string accessToken = xeroToken.AccessToken; string xeroTenantId = xeroToken.Tenants[0].TenantId.ToString(); var AccountingApi = new AccountingApi(); var response = await AccountingApi.GetInvoicesAsync(accessToken, xeroTenantId); var invoices = response._Invoices; return(Json(invoices)); }