public async Task <IHttpActionResult> PostCurrentLocation([FromBody] DriverLocationDTO model) { if (model.DriverId == default(int) || string.IsNullOrWhiteSpace(model.Latitude) || string.IsNullOrWhiteSpace(model.Longitude)) { return(BadRequest()); } var response = await _repository.UpdateCurrentLocation(model); return(Ok(response)); }
public async Task <bool> UpdateCurrentLocation(DriverLocationDTO model) { var driver = context.DriverDetail.FirstOrDefault(a => a.DriverId == model.DriverId); if (ReferenceEquals(driver, null)) { return(false); } driver.CurrentLatitude = model.Latitude; driver.CurrentLongitude = model.Longitude; driver.LastLocationUpdated = DateTime.Now; await context.SaveChangesAsync(); return(true); }
public async Task <DriverLocationDTO> GetCurrentLocation(int driverId) { var driver = await GetDriverDetailAsync(driverId); if (ReferenceEquals(driver, null) || string.IsNullOrWhiteSpace(driver.CurrentLatitude) || string.IsNullOrWhiteSpace(driver.CurrentLongitude)) { return(null); } var model = new DriverLocationDTO { DriverId = driverId, Latitude = driver.CurrentLatitude, Longitude = driver.CurrentLongitude }; return(model); }
public HttpResponseMessage AddDriver(DriverLocationDTO data) { DriverLocationHelper.addDriver(data); return Request.CreateResponse(HttpStatusCode.OK, true); }
public JsonResult WorkShiftStarted(int Id, string Latitude, string Longitude, string Accuracy, string TimeStart) { try { if (Latitude != null && Longitude != null) { DriverLocationDTO driverLocation = new DriverLocationDTO() { id = Id, latitude = double.Parse(Latitude, CultureInfo.InvariantCulture), longitude = double.Parse(Longitude, CultureInfo.InvariantCulture), startedTime = DateTime.Now, updateTime = DateTime.Now, name = ((Session["User"] as UserDTO).UserName) }; carManager.StartWorkEvent(Id, DateTime.Now.ToString()); DriverLocationHelper.addDriver(driverLocation); CoordinatesExDTO coordinates = new CoordinatesExDTO { DriverId = Id, Latitude = double.Parse(Latitude, CultureInfo.InvariantCulture), Longitude = double.Parse(Longitude, CultureInfo.InvariantCulture), Accuracy = double.Parse(Accuracy, CultureInfo.InvariantCulture), AddedTime = DateTime.Parse(TimeStart) }; driverManager.AddDriverLocation(coordinates); } return Json(true); } catch (Exception e) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return Json(false); }
public static void addDriver(DriverLocationDTO data) { Contest.Clients.All.driverStart(data); }