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);
                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"));
        }
        // 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));
        }
示例#3
0
 public PayrollAuApiTests()
 {
     instance = new PayrollAuApi();
 }