public IEnumerable <TimeCardModel> LastRecordedPunches(GeotabInfoModel driver) { Log.MethodStart(); List <TimeCardModel> driverTimePunches = new List <TimeCardModel>(); LastRecordedTime lastTime = new LastRecordedTime(); employeeNumber = driver.EmployeeNumber; DateTime tempDate = lastTime.ReadLastRunFile().AddDays(-14); //Log.Info($"Getting paycom punches from {tempDate} for {employeeNumber}..."); long startDate = DateTimeExtensions.DateTimetoUnixTimeStamp(tempDate); string url = string.Format(punchAuditWithDate, employeeNumber, startDate); try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Add("Authorization", AUTH_HEADER); HttpResponseMessage result = client.GetAsync(url).Result; if (result.StatusCode != HttpStatusCode.OK && result.StatusCode != HttpStatusCode.PartialContent) { return(null); } string resultData = result.Content.ReadAsStringAsync().Result; PunchAuditResponseModel data = JsonConvert.DeserializeObject <PunchAuditResponseModel>(resultData); if (data.errors.FirstOrDefault() == "No Content Found") { Log.Info($"No recent punches for {employeeNumber} since {tempDate}..."); return(null); } ActiveResponseModel[] punchData = data.data.Active; foreach (var activePunch in punchData) { TimeCardModel currentTimeCard = new TimeCardModel(); //var change = TimeSpan.Parse(activePunch.punchtime.TrimEnd(new char[] { ' ', 'A', 'M', 'P' })); DateTime temporaryDate = DateTime.Parse($"{activePunch.punchdate} {activePunch.punchtime}"); currentTimeCard.FirstName = driver.FirstName; currentTimeCard.LastName = driver.LastName; currentTimeCard.EmployeeNumber = driver.EmployeeNumber; currentTimeCard.PunchDateTimeInUnix = TimeZoneConverter.ConvertToUtcFromTimeZone(driver.Timezone, temporaryDate); //currentTimeCard.PunchDateTimeInUnix = DateTime.Parse($"{activePunch.punchdate} {activePunch.punchtime}").ConvertToUtcFromEastern().DateTimetoUnixTimeStamp(); currentTimeCard.PunchDate = $"{activePunch.punchdate} {activePunch.punchtime}"; currentTimeCard.PunchType = activePunch.punchtype; driverTimePunches.Add(currentTimeCard); } //Log.Info($"Last punch for employee {employeeNumber} : {resultData}"); //driverTimePunches = punchData.Select(x => new TimeCardModel //{ // EmployeeNumber = driver.EmployeeNumber, // PunchTime = Convert.ToInt64(x.punchtime.TrimEnd(new char[] { ' ', 'A', 'M', 'P' })), // PunchDate = x.punchdate, // PunchType = x.punchtype //}).ToList(); } return(driverTimePunches.OrderBy(x => x.PunchDate).OrderBy(y => y.PunchTime)); } catch (Exception ex) { Log.Error(ex); Log.Info(ex); throw; } }