/// <summary> /// GET: DriverLocations/Create/id /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ActionResult> Create(string id) { var location = await context.DriverLocations.FindAsync(id); if (location != null) { // Location found, redirect to details return(RedirectToAction("Details", new { Id = location.Driver })); } var user = await context.Users.FindAsync(id); if (user != null && user.UserType.Equals("Driver")) { // Driver found DriverLocation model = new DriverLocation { Driver = user.Username }; return(View(model)); } else { // Driver not found return(HttpNotFound()); } }
private async Task <Driver> GetNearestDriver(double latitude, double longitude, IEnumerable <DriverLocation> driverLocations) { if (driverLocations == null || driverLocations.Count() == 0) { return(null); } DriverLocation nearestDriverLocation = null; double? nearestDistance = 0; foreach (DriverLocation driverLocation in driverLocations) { double distance = await CalculateDistance(driverLocation.Location.Latitude, driverLocation.Location.Longitude, latitude, longitude); if (nearestDriverLocation == null) { nearestDriverLocation = driverLocation; nearestDistance = distance; } else { if (nearestDistance > distance) { nearestDistance = distance; nearestDriverLocation = driverLocation; } } } return(nearestDriverLocation.Driver); }
/// <summary> /// GET: DriverLocations/Delete/id /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ActionResult> Delete(string id) { if (id == null) { // No id return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DriverLocation location = await context.DriverLocations.FindAsync(id); if (location == null) { // No location found return(HttpNotFound()); } var reservations = context.Reservations.Where(r => r.User_Driver.Username == id); if (reservations.Count() != 0) { // On going reservation found var hasRequests = reservations.Where(r => r.Status == "Assigned" || r.Status == "Accepted"); if (hasRequests.Count() != 0) { // Assigned or Accepted reservation is found ViewBag.Message = "Please, respond to the available reservation requests, before attempting to delete this."; } } return(View(location)); }
public MarkerOptions GetMarkerOptions(DriverLocation driverLocation) { var markerOptions = new MarkerOptions() .SetPosition(new LatLng(driverLocation.CurrentLocation.Latitude, driverLocation.CurrentLocation.Longitude)) .Anchor((float)0.5, (float)0.5) .SetRotation((float)driverLocation.Bearing) .Flat(true); return(markerOptions); }
public async Task <ActionResult> Edit([Bind(Include = "Driver,FullAddress,StreetNo,Route,City,Province,ZipCode,Latitude,Longitude")] DriverLocation driverLocation) { if (ModelState.IsValid) { context.Entry(driverLocation).State = EntityState.Modified; await context.SaveChangesAsync(); return(RedirectToAction("Details", new { Id = driverLocation.Driver })); } return(View(driverLocation)); }
/// <summary> /// GET: DriverLocations/Details/id /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ActionResult> Details(string id) { if (id == null) { // No id return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DriverLocation driverLocation = await context.DriverLocations.FindAsync(id); if (driverLocation == null) { // No Location found, redirect to create return(RedirectToAction("Create", new { Id = id })); } return(View(driverLocation)); }
/// <summary> /// GET: DriverLocations/Edit/id /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ActionResult> Edit(string id) { if (id == null) { // No id return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DriverLocation location = await context.DriverLocations.FindAsync(id); if (location == null) { // No location found return(HttpNotFound()); } return(View(location)); }
public async Task <ActionResult> DeleteConfirmed(string id) { // Delete the record and redirect to create DriverLocation location = await context.DriverLocations.FindAsync(id); context.DriverLocations.Remove(location); DriverAvailability availability = await context.DriverAvailabilities.FindAsync(id); if (availability != null) { // Change availability status to false availability.Status = false; } await context.SaveChangesAsync(); return(RedirectToAction("Create", new { Id = location.Driver })); }
public static async Task <IActionResult> CollectDriverInfo([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req) { req.IsValidToken(); //await DriverRepository<Driver>.Initialize(); try { string requestBody = new StreamReader(req.Body).ReadToEnd(); DriverLocation dl = JsonConvert.DeserializeObject <DriverLocation>(requestBody); if (dl == null) { return((ActionResult) new OkObjectResult("Driver Cannot be Null")); } string tableName = "DriverLocation"; if (string.IsNullOrEmpty(dl.DriverId)) { return((ActionResult) new OkObjectResult("A DriverId id needed to process this request.")); } dl.RowKey = dl.DriverId; dl.PartitionKey = "location"; CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=jayappstorage;AccountKey=7W2/D8mqXslm8RXIfNSAv3lT0AtxvIbwFz2At+HBlFEyduECnb3Le3NVaHlR4LrP1luhvkbDtk59Lq8qrVXLbQ==;BlobEndpoint=https://jayappstorage.blob.core.windows.net/;TableEndpoint=https://jayappstorage.table.core.windows.net/;QueueEndpoint=https://jayappstorage.queue.core.windows.net/;FileEndpoint=https://jayappstorage.file.core.windows.net/"); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference(tableName); await table.CreateIfNotExistsAsync(); TableOperation insertOperation = TableOperation.InsertOrReplace(dl); var data = await table.ExecuteAsync(insertOperation); return((ActionResult) new OkObjectResult(data.Result)); }catch (Exception ex) { return((ActionResult) new OkObjectResult(ex)); } }
public void ConvertFromLogEntity(DriverLocation entity) { this.DriverId = entity.DriverId; this.LocationId = entity.LocationId; this.StatusId = entity.StatusId; if (entity.Driver != null) { this.Driver = new DriverDTO(entity.Driver); } if (entity.Location != null) { this.Location = new LocationLagLonDTO(entity.Location); } if (entity.Status != null) { this.Status = new DriverStatusDTO(entity.Status); } }
public string GetDriverLocation(DriverLocation location) { return(HubLocations .FirstOrDefault(item => item.Location.Equals(location)) ?.Url); }
public async Task <RideDTO> CustomerHeartBeatAsync(RideDTO dtoObject) { using (var trans = this.UnitOfWork.DBContext.Database.BeginTransaction()) { Customer customer = await this.UnitOfWork.CustomerRepository.GetByUserId(this.requestInfo.UserId); if (customer == null) { customer = await this.UnitOfWork.CustomerRepository.Create(new Customer() { UserId = this.requestInfo.UserId }); } IEnumerable <Ride> rideEntities = await this.Repository.GetByCustomerId(customer.Id); if (rideEntities.Where(x => x.IsActive).Count() > 0) { Ride activeRide = rideEntities.Where(x => x.IsActive).FirstOrDefault(); if (activeRide != null) { if (activeRide.Driver == null) { Driver nearestDriver = await GetNearestDriver(activeRide.Source.Latitude, activeRide.Source.Longitude); if (nearestDriver != null) { IList <Vehicle> vehiclesEntity = await this.UnitOfWork.VehicleRepository.GetAllByDriverId(nearestDriver.Id); if (vehiclesEntity != null && vehiclesEntity.Count > 0 && vehiclesEntity.First().Package != null && vehiclesEntity.First().PackageID > 0) { activeRide.Driver = nearestDriver; activeRide.DriverId = nearestDriver.Id; activeRide.PackageId = vehiclesEntity.First().PackageID; activeRide.Package = vehiclesEntity.First().Package; activeRide.Vehicle = vehiclesEntity.First(); activeRide.VehicleId = vehiclesEntity.First().Id; await this.Repository.Update(activeRide); await this.UnitOfWork.SaveAsync(); trans.Commit(); } } } else { RideDTO dto = new RideDTO(activeRide); DriverLocation driverLocation = await this.UnitOfWork.DriverLocationRepository.GetByDriverId(activeRide.DriverId.Value); if (driverLocation != null) { dto.Driver.DriverLocation = new DriverLocationDTO(driverLocation); return(dto); } else { return(dto); } } return(new RideDTO(activeRide)); } else { return(null); } } else { return(null); } } }