//Checked public OperationResult Add(NewBusRouteModel busRouteDTO) { OperationResult result = new(); try { Route routeInDB = UnitOfWork.Routes.Get(busRouteDTO.RouteId); Bus busInDB = UnitOfWork.Buses.Get(busRouteDTO.BusId); if (busInDB != null && routeInDB != null) { BusRoute newBusRoute = Mapper.Map <NewBusRouteModel, BusRoute>(busRouteDTO); newBusRoute.Bus = busInDB; newBusRoute.Route = routeInDB; UnitOfWork.BusRoutes.Add(newBusRoute); UnitOfWork.Complete(); result.SetSuccessResult(); } else { result.SetFailureResult("Bus id or route id is invalid."); } } catch (Exception e) { result.SetExceptionResult(e.StackTrace); } return(result); }
public ActionResult GetRoutePlanning(PlanningOptions options) { ReturnObject2 ro = null; try { var route = RoutePlanning.GetRoute(options); object result = null; if (options.TripMode == 1) { result = BusRoute.Parse(route); } else { result = DrivingResult.Parse(route); } ro = new ReturnObject2(); ro.AddData("route", result); } catch (Exception ex) { ro = new ReturnObject2(ex.Message); } return(Json(ro)); }
//checked public OperationResult Update(int busRouteId, NewBusRouteModel newBusRoute) { OperationResult result = new OperationResult(); try { BusRoute busRouteInDB = UnitOfWork.BusRoutes.Get(busRouteId); if (busRouteInDB != null) { Bus busInDb = UnitOfWork.Buses.Get(newBusRoute.BusId); Route routeInDb = UnitOfWork.Routes.Get(newBusRoute.RouteId); if (busInDb != null && routeInDb != null) { Mapper.Map <NewBusRouteModel, BusRoute>(newBusRoute); busRouteInDB.Bus = busInDb; busRouteInDB.Route = routeInDb; UnitOfWork.Complete(); } else { result.SetFailureResult("Invalid bus or route id"); } } else { result.SetFailureResult("No Bus route with this id found."); } } catch (Exception e) { result.SetExceptionResult(e.StackTrace); } return(result); }
public void Part1() { var busRoute = new BusRoute("7,13,x,x,59,x,31,19"); busRoute.GetNextDeparture(939) .Should().Be((59, 944, 5)); }
private static List <BusRoute> CreateRoutes(List <GoogleRoute> googleRoutes, List <ConnexionzRoute> connexionzRoutes) { var googleRoutesDict = googleRoutes.ToDictionary(gr => gr.Name); var routes = connexionzRoutes.Where(r => r.IsActive && googleRoutesDict.ContainsKey(r.RouteNo)); return(routes.Select(r => BusRoute.Create(r, googleRoutesDict)).ToList()); }
public IHttpActionResult PutBusRoute(string id, BusRoute busRoute) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != busRoute.Id) { return(BadRequest()); } db.Entry(busRoute).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BusRouteExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private static void Main(string[] args) { BusRoute pBus1 = new BusRoute(); Passenger pPassenger1 = new Passenger("0001", new DateTime(1991, 8, 19), 20); Passenger pPassenger2 = new Passenger("0002", new DateTime(1993, 10, 1), 22); Passenger pPassenger3 = new Passenger("0003", new DateTime(2005, 10, 1), 22); pBus1.PassengerList.Add(pPassenger1); pBus1.PassengerList.Add(pPassenger2); pBus1.PassengerList.Add(pPassenger3); pBus1.PassengerList.Add(pPassenger3); pBus1.Number = "130"; List <Passenger> pList = pBus1.GetUnticketedList(); Console.WriteLine($"Пассажиров-молодых зайцев: {pList.Count} шт."); foreach (Passenger pAr in pList) { Console.WriteLine(pAr.CardNumber); } /* * * BusRoute pBus2 = new BusRoute(); * pBus2.Number = "131"; * pBus2.PassengerList.Add(pPassenger3); * pBus2.PassengerList.Add(pPassenger3); * pBus2.PassengerList.Add(pPassenger3); * * * Console.WriteLine(pBus1.Number); */ Console.ReadKey(); }
public static IEnumerable <BusRoute> GetRoutes(BusContext db) { var queryResult = from r in db.BusRoutes select BusRoute.FromMemento(r); return(queryResult.AsEnumerable()); }
public async Task <IActionResult> Edit(int id, [Bind("Id,BusId,RouteId")] BusRoute busRoute) { if (id != busRoute.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(busRoute); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BusRouteExists(busRoute.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BusId"] = new SelectList(_context.Bus, "Id", "LicencePlate", busRoute.BusId); ViewData["RouteId"] = new SelectList(_context.Route, "Id", "Name", busRoute.RouteId); return(View(busRoute)); }
private void GetBurnabyStopResponse(IAsyncResult result) { string json = string.Empty; try { HttpWebRequest request = (HttpWebRequest)result.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); json = reader.ReadToEnd(); } catch (Exception) { return; } JArray stopObject = JArray.Parse(json); string routeNo = stopObject[0]["RouteNo"].ToString(); string routeName = stopObject[0]["RouteName"].ToString(); BusRoute route = new BusRoute(routeNo, routeName); JArray times = stopObject[0]["Schedules"] as JArray; foreach (JObject obj in times) { string time = obj["ExpectedLeaveTime"].ToString(); route.AddRouteTime(time); } Deployment.Current.Dispatcher.BeginInvoke(() => { BusRoutes.Add(route); OnPropertyChanged("BusRoutes"); }); }
public async Task <IActionResult> Edit(string id, [Bind("BusRouteCode,RouteName")] BusRoute busRoute) { if (id != busRoute.BusRouteCode) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(busRoute); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BusRouteExists(busRoute.BusRouteCode)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(busRoute)); }
public void Part2() { var busRoute = new BusRoute("7,13,x,x,59,x,31,19"); busRoute.Part2() .Should().Be(1068781); }
public ArrivalBundle(BusStop stop, BusRoute bus, bool live) { this.Stop = stop; this.Bus = bus; this.Live = live; this.CommonDestination=bus.Long_Name; }
public IHttpActionResult PostBusRoute(BusRoute busRoute) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.BusRoutes.Add(busRoute); try { db.SaveChanges(); } catch (DbUpdateException) { if (BusRouteExists(busRoute.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = busRoute.Id }, busRoute)); }
public ActionResult Book(int?Id, int BusRouteId, BusRoute busRoute, UserTicket userTicket) { var route = _context.BusRoutes.Where(o => o.Id == userTicket.BusRouteId).FirstOrDefault(); var fare = _context.Buses.Where(o => o.Id == route.BusId).FirstOrDefault(); List <string> tickets = new List <string>(); for (var i = 1; i <= userTicket.ReservedSeats; i++) { var randomTicket = Guid.NewGuid().ToString().Substring(0, 6); tickets.Add(randomTicket); } string multipleTickets = string.Join(",", tickets); userTicket.TicketId = multipleTickets; _context.SaveChanges(); if (userTicket.ReservedSeats >= 1) { userTicket.PaidFare = fare.Price * userTicket.ReservedSeats; } busRoute.Id = route.Id; busRoute.BusId = route.BusId; busRoute.RouteId = route.RouteId; busRoute.ArrivalTime = route.ArrivalTime; busRoute.DepartureTime = route.DepartureTime; busRoute.ReservedSeats = route.ReservedSeats + userTicket.ReservedSeats; _context.Set <BusRoute>().AddOrUpdate(busRoute); _context.SaveChanges(); _context.UserTickets.Add(userTicket); _context.SaveChanges(); return(RedirectToAction("Ticket", new { userTicket.Id })); }
public void AddBusRoute(BusRoute busRoute) { using (ApplicationDbContext db = new ApplicationDbContext()) { db.BusRoutes.Add(busRoute); db.SaveChanges(); } }
public static void AddRoute(BusContext db, string name) { var id = new BusRouteId(int.Parse(name)); var r = new BusRoute(id, name); db.Add(r.State); db.SaveChanges(); }
public void addBusRoute(BusRoute br) { allBusRoutes.Add(br); if (!focusedBusRoute) { focusedBusRoute = br; } }
public ArrivalBundle(BusStop stop, BusRoute bus, List<DateTime> times, bool live=false) { this.Stop = stop; this.Bus = bus; this.Times = times; this.Live = live; this.CommonDestination=bus.Long_Name; }
private void Start_InitializeRoute() { if (!busRoute) { busRoute = GetComponentInParent <BusRoute>(); } currentWayPoint = busRoute.getNextWayPoint(null); nextWayPoint = busRoute.getNextWayPoint(currentWayPoint); }
public ArrivalBundle(Arrival firstArrival) { this.Bus=firstArrival.Bus; this.Stop=firstArrival.Stop; this.Live=firstArrival.Live; Times=new List<DateTime>(); Times.Add(firstArrival.Time); this.CommonDestination=firstArrival.Destination; }
public void DeleteBusRoute(int id) { using (ApplicationDbContext db = new ApplicationDbContext()) { BusRoute busRoute = db.BusRoutes.Find(id); db.BusRoutes.Remove(busRoute); db.SaveChanges(); } }
public void UpdateBusRoute(BusRoute busRoute) { using (ApplicationDbContext db = new ApplicationDbContext()) { db.BusRoutes.Attach(busRoute); db.Entry(busRoute).State = EntityState.Modified; db.SaveChanges(); } }
// Update is called once per frame void Update() { BusRoute br = hud.getSceneManager().getFocusedBusRoute(); if (br) { txt_routeName.text = "Route: " + br.routeName; } }
/// <summary> /// FullBusRoute.xml - All Bus Route Available /// StaticData._busRoute /// </summary> private void LoadDataFile() { if (StaticData._busRoute == null) { StaticData._busRoute = new ObservableCollection <BusRoute>(); XDocument doc = XDocument.Load("Data/FullBusRoute.xml"); ObservableCollection <LocationPointWithId> tempGoLocationPoint; ObservableCollection <LocationPointWithId> tempBackLocationPoint; foreach (var item in doc.Element("root").Elements("BusRoute")) { tempGoLocationPoint = new ObservableCollection <LocationPointWithId>(); tempBackLocationPoint = new ObservableCollection <LocationPointWithId>(); foreach (var locationPoint in item.Element("GoDirection").Elements("LocationPoint")) { var newLocationPoint = new LocationPointWithId() { id = locationPoint.Attribute("Id").Value, longitude = Convert.ToDouble(locationPoint.Element("Lon").Value), latitude = Convert.ToDouble(locationPoint.Element("Lat").Value), }; tempGoLocationPoint.Add(newLocationPoint); } foreach (var locationPoint in item.Element("BackDirection").Elements("LocationPoint")) { var newLocationPoint = new LocationPointWithId() { id = locationPoint.Attribute("Id").Value, longitude = Convert.ToDouble(locationPoint.Element("Lon").Value), latitude = Convert.ToDouble(locationPoint.Element("Lat").Value), }; tempBackLocationPoint.Add(newLocationPoint); } var newBusRoute = new BusRoute() { id = item.Attribute("BusId").Value, goDirection = tempGoLocationPoint, backDirection = tempBackLocationPoint, }; StaticData._busRoute.Add(newBusRoute); } } //Enable Async //StorageFile destinationFile = await ApplicationData.Current.LocalFolder.CreateFileAsync( // "placeHolderData.dat", CreationCollisionOption.ReplaceExisting); //busRouteStatusTextBlock.Text = "Bus Routes Data Ready"; }
public BusTrip(BusRoute myRoute, Destination origin, Destination destination, bool weekdays, TimeSpan originArrival, TimeSpan destArrival, bool weekends, bool holidays) { this.origin=origin; this.clockTimeOrigin=originArrival; this.clockTimeDestination=destArrival; this.destination=destination; OperatesHolidays=holidays; OperatesWeekdays= weekdays; OperatesWeekends=weekdays; }
internal void OnRouteChanged(BusRoute selectedRoute, RouteBeginTime.ScheduleDays scheduleDays, int routeVariant) { RouteDetailsForRoute = RouteDetails.Where(route => route.RouteId == selectedRoute.Id && route.RouteVariantId == routeVariant).ToList(); BeginTimesForRoute = RouteBeginTimes.Where(beginTime => beginTime.RouteId == selectedRoute.Id && beginTime.Days == scheduleDays && beginTime.RouteVariant == routeVariant).OrderBy(beginTime => beginTime.Time).ToList(); RouteVariants = Enumerable.Range(0, selectedRoute.VariantsNum).ToList(); OnPropertyChanged(nameof(RouteDetailsForRoute)); OnPropertyChanged(nameof(BeginTimesForRoute)); OnPropertyChanged(nameof(RouteVariants)); }
public IHttpActionResult GetBusRoute(string id) { BusRoute busRoute = db.BusRoutes.Find(id); if (busRoute == null) { return(NotFound()); } return(Ok(busRoute)); }
public async Task <IActionResult> Create([Bind("BusRouteCode,RouteName")] BusRoute busRoute) { if (ModelState.IsValid) { _context.Add(busRoute); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(busRoute)); }
private void initializeBusRoutes() { for (int i = 0; i < db_BusRoutes.Count; i++) { BusRoute br = Instantiate(simResources.busRoute_prefab); br.routeName = db_BusRoutes[i]; br.transform.parent = transform; busRoutes.Add(br); sceneManager.addBusRoute(br); } }
public override bool Equals(object obj) { if (obj is BusRoute) { BusRoute br = obj as BusRoute; return(string.Compare(br.FromName, FromName) == 0 && string.Compare(br.ToName, ToName) == 0 && string.Compare(br.RouteName, RouteName) == 0); } return(false); }
public ActionResult Edit(BusRoute busRoute) { if (!ModelState.IsValid) { var cities = db.GetCities().AsEnumerable(); ViewBag.FromCityId = new SelectList(cities, "Id", "CityName"); ViewBag.ToCityId = new SelectList(cities, "Id", "CityName"); return(View(busRoute)); } db.UpdateBusRoute(busRoute); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Id,BusId,RouteId")] BusRoute busRoute) { if (ModelState.IsValid) { _context.Add(busRoute); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BusId"] = new SelectList(_context.Bus, "Id", "LicencePlate", busRoute.BusId); ViewData["RouteId"] = new SelectList(_context.Route, "Id", "Name", busRoute.RouteId); return(View(busRoute)); }
public ActionResult Edit(int id) { BusRoute busRoute = db.GetBusRoute(id); var cities = db.GetCities().AsEnumerable(); ViewBag.FromCityId = new SelectList(cities, "Id", "CityName"); ViewBag.ToCityId = new SelectList(cities, "Id", "CityName"); if (busRoute == null) { return(HttpNotFound()); } return(View(busRoute)); }
public void testCreateRoute() { BusRoute r = new BusRoute("Route 222 to Bridge to Nowhere"); Assert.AreEqual("Bridge to Nowhere", r.Long_Name); Assert.AreEqual("222",r.Short_Name); }