示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("StopId,StopNumber,Longitude,Lattitude,RouteId")] RouteStops routeStops)
        {
            if (id != routeStops.StopId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(routeStops);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RouteStopsExists(routeStops.StopId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(routeStops));
        }
示例#2
0
 private static RouteStops routeStops_ToDTO(RouteStops routeStops) =>
 new RouteStops
 {
     Route_IdRoute      = routeStops.Route_IdRoute,
     BusStop_IdBusStop  = routeStops.BusStop_IdBusStop,
     positionRouteStops = routeStops.positionRouteStops
 };
        private void RouteDirection_Tap(object sender, Microsoft.Phone.Controls.GestureEventArgs e)
        {
            RouteStops routeStops = (sender as FrameworkElement).DataContext as RouteStops;

            viewModel.CurrentViewState.CurrentRoutes = new List <Route>()
            {
                (Route)routeStops.route
            };

            viewModel.CurrentViewState.CurrentRoute          = routeStops.route;
            viewModel.CurrentViewState.CurrentRouteDirection = routeStops;

            viewModel.CurrentViewState.CurrentStop = viewModel.CurrentViewState.CurrentRouteDirection.stops[0];
            foreach (Stop stop in viewModel.CurrentViewState.CurrentRouteDirection.stops)
            {
                // TODO: Make this call location-unknown safe.  The CurrentLocation could be unknown
                // at this point during a tombstoning scenario
                GeoCoordinate location = viewModel.LocationTracker.CurrentLocation;

                if (viewModel.CurrentViewState.CurrentStop.CalculateDistanceInMiles(location) > stop.CalculateDistanceInMiles(location))
                {
                    viewModel.CurrentViewState.CurrentStop = stop;
                }
            }

            Navigate(new Uri("/DetailsPage.xaml", UriKind.Relative));
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is RouteStops)
            {
                RouteStops routeStops = (RouteStops)value;

                if (routeStops.encodedPolylines != null)
                {
                    List <LocationCollection> polylines = new List <LocationCollection>();
                    foreach (PolyLine pl in routeStops.encodedPolylines)
                    {
                        LocationCollection polyline = new LocationCollection();
                        pl.Coordinates.ForEach(coordinate => polyline.Add(new GeoCoordinate(coordinate.Latitude, coordinate.Longitude)));
                        polylines.Add(polyline);
                    }

                    return(polylines);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("StopId,StopNumber,Longitude,Lattitude,RouteId")] RouteStops routeStops)
        {
            if (ModelState.IsValid)
            {
                _context.Add(routeStops);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(routeStops));
        }
示例#6
0
        public JsonResult GetStops(string id, string inOrOut)
        {
            string                url       = serviceUrlBase + "stopsbyroute?api_key=" + apiKey + "&route=" + id + "&format=json";
            WebClient             client    = new WebClient();
            List <SelectListItem> stopsList = new List <SelectListItem>();

            stopsList.Add(new SelectListItem {
                Value = "-1", Text = "Select your stop"
            });
            try
            {
                string output = client.DownloadString(url);
                stopOutput = GetJsonDataFromFile(stopsFile);

                StationStops stops  = JsonConvert.DeserializeObject <StationStops>(output);
                RouteStops   stops2 = JsonConvert.DeserializeObject <RouteStops>(output);

                //var theseStops = from stop in stops2.route
                //                 where stop.route_id == id
                //                 select stop;

                foreach (var stop in stops.direction)
                {
                    //foreach (var thisStop in stop.stop)
                    //{
                    //    stopsList.Add(new SelectListItem { Text = thisStop.stop_name, Value = thisStop.stop_id });
                    //}
                    //foreach (var stop in item)
                    if (stop.direction_id == inOrOut)
                    {
                        foreach (var thisStop in stop.stop)
                        {
                            stopsList.Add(new SelectListItem {
                                Text = thisStop.stop_name, Value = thisStop.stop_order
                            });
                        }
                    }
                }
            }
            catch (Exception e)
            {
                stopsList.Add(new SelectListItem {
                    Text = "No stop response from the Commuter Rail.", Value = "-1"
                });
                stopsList.Add(new SelectListItem {
                    Text = e.Message, Value = "-2"
                });
            }
            return(Json(new SelectList(stopsList, "Value", "Text")));
        }
示例#7
0
        public async Task <ActionResult <Message> > CreateRouteStops(RouteStops routeStops)
        {
            var routeStopsAux = new RouteStops
            {
                Route_IdRoute      = routeStops.Route_IdRoute,
                BusStop_IdBusStop  = routeStops.BusStop_IdBusStop,
                positionRouteStops = routeStops.positionRouteStops
            };

            _context.RouteStops_s.Add(routeStopsAux);
            await _context.SaveChangesAsync();

            var message = new Message("Route Stop successfully added");

            return(message);
        }
示例#8
0
        public async Task <ActionResult <RouteStops> > DeleteRouteStopsAccordingToIdRouteAndIdStopAndPosition(int route_IdRoute, int busStop_IdBusStop, int PositionRouteStops)
        {
            RouteStops routeStops = new RouteStops
            {
                Route_IdRoute      = route_IdRoute,
                BusStop_IdBusStop  = busStop_IdBusStop,
                positionRouteStops = PositionRouteStops
            };

            if (routeStops == null)
            {
                return(NotFound());
            }

            _context.RouteStops_s.Remove(routeStops);
            await _context.SaveChangesAsync();

            return(routeStops_ToDTO(routeStops));
        }
示例#9
0
        public async Task <IActionResult> Create([Bind("StudentId,FirstName,LastName,ParentFirstName,ParentLastName,ParentPhoneNumber,StreetAddress,City,ZipCode,StopId,Longitude,Lattitude")] GeocodedStudent students)
        {
            Students student = new Students();

            if (ModelState.IsValid)
            {
                student.FirstName         = students.FirstName;
                student.LastName          = students.LastName;
                student.ParentFirstName   = students.ParentFirstName;
                student.ParentLastName    = students.ParentLastName;
                student.ParentPhoneNumber = students.ParentPhoneNumber;
                student.StreetAddress     = students.StreetAddress;
                student.City    = students.City;
                student.ZipCode = students.ZipCode;

                int studentStopId = 0;
                int studentId     = 0;
                using (var context = _context)
                {
                    RouteStops studentStop = new RouteStops();
                    studentStop.Lattitude = students.Lattitude;
                    studentStop.Longitude = students.Longitude;

                    context.Add(studentStop);
                    context.Add(student);
                    context.SaveChanges();

                    studentStopId = studentStop.StopId;
                    studentId     = students.StudentId;

                    student.StopId = studentStopId;
                    context.Update(student);
                    context.SaveChanges();
                    await context.SaveChangesAsync();
                }

                return(RedirectToAction(nameof(Index)));

                //Need to figure out a way to assign the studentStopId to the newly created routeStops object
            }
            return(View(student));
        }
示例#10
0
        public JobNode(Job job)
        {
            Job        = job;
            Id         = job.Id;
            RouteStops = Job.RouteStops.ToList();

            if (RouteStops.Count > 0)
            {
                // This assumes that the internal time widows of the job are feasable
                var       firstStop  = RouteStops.First();
                RouteStop secondStop = null;
                if (RouteStops.Count > 1)
                {
                    secondStop = RouteStops[1];
                }

                WindowStart = firstStop.WindowStart;
                WindowEnd   = secondStop != null &&
                              secondStop.WindowStart < firstStop.WindowEnd ? secondStop.WindowStart : firstStop.WindowEnd;
            }
        }
示例#11
0
        //private ObservableCollection<CustomPin> customPins = new ObservableCollection<CustomPin> ();
        //public ObservableCollection<CustomPin> CustomPins { get { return customPins; } set { customPins = value; OnPropertyChanged(); } }

        async Task GetClosestAsync()
        {
            if (RouteStops.Count == 0)
            {
                return;
            }

            if (IsBusy)
            {
                return;
            }
            try
            {
                var location = await Geolocation.GetLastKnownLocationAsync();

                if (location == null)
                {
                    location = await Geolocation.GetLocationAsync(new GeolocationRequest
                    {
                        DesiredAccuracy = GeolocationAccuracy.Medium,
                        Timeout         = TimeSpan.FromSeconds(30)
                    });
                }

                var first = RouteStops.OrderBy(m => location.CalculateDistance(
                                                   new Location(m.Latitude, m.Longitude), DistanceUnits.Miles))
                            .FirstOrDefault();

                await Application.Current.MainPage.DisplayAlert("", first.Name + " " +
                                                                first.Location + " " + first.Latitude + " " + first.Longitude, "OK");

                var _myPosition = new Position(first.Latitude, first.Longitude);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Something is wrong",
                                                                "Unable to get location! :(", "OK");
            }
        }
示例#12
0
        public void SetStopInfo(int stopId, int stopNumber, int routeId)
        {
            using (var context = _context)
            {
                var stop = context.RouteStops.AsNoTracking()
                           .Where(x => x.StopId == stopId).FirstOrDefault();

                RouteStops updateStop = new RouteStops();
                updateStop.StopId     = stop.StopId;
                updateStop.StopNumber = stopNumber;
                updateStop.Longitude  = stop.Longitude;
                updateStop.Lattitude  = stop.Lattitude;
                updateStop.RouteId    = routeId;

                context.Update(updateStop);
                context.SaveChanges();



                return;
            }
        }
示例#13
0
        public async Task GetRouteStopsAsync()
        {
            if (IsBusy)
            {
                return;
            }
            try
            {
                var client = new HttpClient();
                var json   = await client.GetStringAsync("https://catchall02.azurewebsites.net/tables/geolocationobject?ZUMO-API-VERSION=2.0.0");

                var all = RouteStop.FromJson(json);
                RouteStops.ReplaceRange(all);
                Title = $"Route Stops ({RouteStops.Count})";
            }
            catch (System.Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Something went wrong", "Cancel");
            }
            finally
            {
                IsBusy = false;
            }
        }
示例#14
0
        public TerminalJobType GetTerminalJobType(IEnumerable <int?> terminalLocationIds)
        {
            var result = TerminalJobType.Unspecified;

            if (RouteStops != null && terminalLocationIds != null && terminalLocationIds.Any())
            {
                var matchingRouteStop = RouteStops.FirstOrDefault(p => p.LocationId != null && terminalLocationIds.Contains(p.LocationId));
                if (matchingRouteStop != null)
                {
                    switch (matchingRouteStop.StopAction.ShortName)
                    {
                    case "PEWC":
                    case "DLWC":
                        result = TerminalJobType.Export;
                        break;

                    case "PLWC":
                        result = TerminalJobType.Import;
                        break;
                    }
                }
            }
            return(result);
        }
示例#15
0
        public static void Initialize(SchoolContext context)
        {
            context.Database.EnsureCreated();

            using (var dbContextTransaction = context.Database.BeginTransaction())
            {
                try
                {
                    if (!context.RouteStops.Any())
                    {
                        var routeStops = new RouteStops[]
                        {
                            new RouteStops {
                            },
                            new RouteStops {
                            },
                            new RouteStops {
                            },
                            new RouteStops {
                            },
                        };

                        foreach (RouteStops rs in routeStops)
                        {
                            context.RouteStops.Add(rs);
                        }

                        context.SaveChanges();
                    }

                    if (!context.Students.Any())
                    {
                        var students = new Students[]
                        {
                            new Students {
                                FirstName         = "Timon", LastName = "Mannings", ParentFirstName = "Wade", ParentLastName = "Mannings",
                                ParentPhoneNumber = "9374417246", StreetAddress = "9353 County Road 101", City = "Belle Center", ZipCode = "43310", StopId = 3
                            },
                            new Students {
                                FirstName         = "Bryan", LastName = "Huddleston", ParentFirstName = "Bryan", ParentLastName = "Huddleston",
                                ParentPhoneNumber = "5561234532", StreetAddress = "2307 Liberty Street", City = "West Chester", ZipCode = "45530", StopId = 4
                            },
                            new Students {
                                FirstName         = "Braden", LastName = "Lance", ParentFirstName = "Scott", ParentLastName = "Lance",
                                ParentPhoneNumber = "5567898965", StreetAddress = "2311 Forest Hill Drive", City = "West Chester", ZipCode = "45211", StopId = 5
                            },
                            new Students {
                                FirstName         = "Nathan", LastName = "Boehringer", ParentFirstName = "Jim", ParentLastName = "Boehringer",
                                ParentPhoneNumber = "5563214756", StreetAddress = "5834 Vine Street", City = "Clifton", ZipCode = "45532", StopId = 6
                            },
                        };

                        foreach (Students s in students)
                        {
                            context.Students.Add(s);
                        }

                        context.SaveChanges();
                    }

                    if (!context.School.Any())
                    {
                        var schools = new School[]
                        {
                            new School {
                                SchoolName = "Benjamin Logan Highschool", SchoolAddress = "2424 County Road 47", SchoolCity = "Bellefontaine", SchoolZipCode = "43311",
                                NumbBuses  = 59, ArrivalTime = new TimeSpan(7, 45, 0), DepartureTime = new TimeSpan(15, 15, 0), RouteGroup = 'A',
                            }
                        };

                        foreach (School s in schools)
                        {
                            context.School.Add(s);
                        }

                        context.SaveChanges();
                    }

                    if (!context.Buses.Any())
                    {
                        var buses = new Buses[]
                        {
                            new Buses {
                                BusNumb = 1, Capacity = 30, Condition = "FUNCTIONAL", Handicap = "YES"
                            },
                            new Buses {
                                BusNumb = 2, Capacity = 30, Condition = "FUNCTIONAL", Handicap = "NO"
                            },
                            new Buses {
                                BusNumb = 3, Capacity = 30, Condition = "NOT FUNCTIONAL", Handicap = "NO"
                            },
                            new Buses {
                                BusNumb = 4, Capacity = 30, Condition = "FUNCTIONAL", Handicap = "NO"
                            },
                            new Buses {
                                BusNumb = 5, Capacity = 30, Condition = "NOT FUNCTIONAL", Handicap = "NO"
                            },
                            new Buses {
                                BusNumb = 6, Capacity = 30, Condition = "FUNCTIONAL", Handicap = "NO"
                            },
                        };

                        foreach (Buses b in buses)
                        {
                            context.Buses.Add(b);
                        }

                        context.SaveChanges();
                    }

                    if (!context.Drivers.Any())
                    {
                        var drivers = new Drivers[]
                        {
                            new Drivers {
                                FirstName    = "Timon", LastName = "Mannings", DriverPhoneNumber = "9374417525", Condition = "INACTIVE", StartAddress = "9353 County Road 101", StartCity = "Belle Center",
                                StartZipCode = "43310"
                            },
                            new Drivers {
                                FirstName    = "Nathan", LastName = "Boehringer", DriverPhoneNumber = "5562548734", Condition = "ACTIVE", StartAddress = "9353 County Road 101", StartCity = "Belle Center",
                                StartZipCode = "43310"
                            },
                            new Drivers {
                                FirstName    = "Bryan", LastName = "Huddleston", DriverPhoneNumber = "5562538313", Condition = "ACTIVE", StartAddress = "9353 County Road 101", StartCity = "Belle Center",
                                StartZipCode = "43310"
                            }
                        };

                        foreach (Drivers d in drivers)
                        {
                            context.Drivers.Add(d);
                        }

                        context.SaveChanges();
                    }

                    if (!context.Routes.Any())
                    {
                        var routes = new Routes[]
                        {
                            new Routes {
                                RouteGroup = 'A'
                            },
                            new Routes {
                                RouteGroup = 'A'
                            },
                            new Routes {
                                RouteGroup = 'A'
                            },
                        };

                        foreach (Routes r in routes)
                        {
                            context.Routes.Add(r);
                        }

                        context.SaveChanges();
                    }

                    dbContextTransaction.Commit();
                    return;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.InnerException);
                    return;
                    //Log, handle or absorbe I don't care ^_^
                }
            }
        }