public async Task <bool> ClockInAsync(ClockInDto clockInDto) { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(TripApiUrlBase); string requestUrl = $"PostClockIn"; var request = GetRequestHeaders(HttpMethod.Get, requestUrl); var jsonContent = JsonConvert.SerializeObject(clockInDto); request.Content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); var result = await client.SendAsync(request).ConfigureAwait(false); if (result.IsSuccessStatusCode) { string serializedJson = await result.Content.ReadAsStringAsync().ConfigureAwait(false); clockInDto = JsonConvert.DeserializeObject <ClockInDto>(serializedJson); return(true); } else { return(false); } } } catch (Exception ex) { var message = ex.Message; return(false); } }
public static async Task <bool> ClockIn(ClockInDto clockInDto) { bool clockedIn = await Task.Run <bool>(async() => { var api = new ApiClient.ApiClient(Credentials.TruckNumber, Credentials.ApiKey); return(await api.ClockInAsync(clockInDto)); }); if (clockedIn) { ClockInOutState = "ClockOut"; } return(clockedIn); }
public IHttpActionResult PostClockIn([FromBody] ClockInDto clockIn) { Log.Info($"Clock In for job {clockIn.JobId.ToString()} at {clockIn.ActualClockIn.ToString()}"); var job = db.Jobs.Include("TripRoute.Trip").FirstOrDefault(j => j.JobId.Equals(clockIn.JobId)); if (VerifyBasicAuthCredentials(job.ActualTruckId.Value)) { if (job != null && job.TripRoute.TripStatusId >= Enums.TripStatusEnum.Dispatched.GetHashCode() && job.TripRoute.TripStatusId < Enums.TripStatusEnum.Completed.GetHashCode() && job.TripStatusId == Enums.TripStatusEnum.Dispatched.GetHashCode()) { try { job.ActualClockIn = clockIn.ActualClockIn; job.ActualDriverVendorWorkerId = job.TripRoute.Trip.DriverVendorWorkerId; job.TripRoute.TripStatusId = Enums.TripStatusEnum.InProcess.GetHashCode(); job.TripStatusId = Enums.TripStatusEnum.InProcess.GetHashCode(); if (job.JobRequiresWeighInOut) { job.ActualWeightIn = clockIn.ActualWeightIn; } db.SaveChanges(); return(Ok(clockIn)); } catch (Exception ex) { Log.Error("Error: " + ex.InnerException + "Message: " + ex.Message + "StackTrace: " + ex.StackTrace); return(NotFound()); } } } else { return(Unauthorized()); } return(NotFound()); }
public async void OnClockInOutClicked(object sender, EventArgs e) { if ((sender as Button).Text.Contains("Clock In")) { ClockInDto clockInDto = new ClockInDto(); clockInDto.JobId = CurrentJob.JobId; // long.Parse((sender as Button).CommandParameter.ToString()); clockInDto.ActualClockIn = DateTime.Now; if (CurrentJob.JobRequiresWeighInOut) { double weighInValue = 0.0; if (double.TryParse(weighInEntry.Text, out weighInValue)) { clockInDto.ActualWeightIn = weighInValue; } else { await DisplayAlert("Weigh In is Required", "Please Proceed directly to the scales and Weigh In before doing any work on the site.", "OK"); return; } } bool clockedIn = await TripContext.ClockIn(clockInDto); if (clockedIn) { SetClockOutDisplay(sender); } else { (sender as Button).Text = "Clock In failed. Please re-try. \n (" + DateTime.Now + ")"; } } else { SetSiteCompleteDisplay(sender); } }