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));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public HttpResponseMessage AddDriver(DriverLocationDTO data)
 {
     DriverLocationHelper.addDriver(data);
     return Request.CreateResponse(HttpStatusCode.OK, true);
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 public static void addDriver(DriverLocationDTO data)
 {
     Contest.Clients.All.driverStart(data);
 }