コード例 #1
0
 public ActionResult AddNewRoute(List<int> stopIds, string routeName, int busId, bool startsAtWork, string driverLicense)
 {
     DatabaseInterface db = new DatabaseInterface();
     if (!db.IsRouteNameUnique(routeName))
         return Json("false");
     int routeId;
     if (startsAtWork)
         routeId = db.GetNextLowRouteId();
     else
         routeId = db.GetNextHighRouteId();
     List<Stop> stops = new List<Stop>();
     foreach (int id in stopIds)
     {
         stops.Add(db.GetStopByStopId(id));
     }
     List<Route> routes = new List<Route>();
     routes = db.GetAvailableRoutes();
     db.AssignBusToRoute(busId, routeId);
     db.AssignDriverToRoute(driverLicense, routeId);
     Route route = new Route()
     {
         Stops = stops,
         Driver = db.GetDriverByDriverLicense(driverLicense),
         Name = routeName,
         RouteId = routeId,
         Id = ObjectId.GenerateNewId(),
         Bus = db.GetBusByBusId(busId)
     };
     db.AddRoute(route);
     return Json(new
     {
        success = "true",
        id = route.Id.ToString()
     });
 }