public RouteWayPoint(RouteWayPointView routeWayPointView) { RouteId = routeWayPointView.RouteId; LineId = routeWayPointView.LineId; Latitude = routeWayPointView.Latitude; Longitude = routeWayPointView.Longitude; }
public string CreateUpdate(RouteWayPointView[] routeView) { //For now routeView cannot be null: it as a start and an end var routeId = routeView[0].RouteId; //routeId=0 this is a route creation //Retrieve the route Route route = null; if (routeId > 0) route = db.Route.Find(routeId); //if (route == null) //{ // //If we create a new route we need an active session to find user ID // if (Session["userId"] == null) return "/User/Login/"; // RedirectToAction("Login", "User"); //Expired session, go to User/Login // route = new Route(); // route.UserId = (int)Session["userId"]; //} //Update the route //route.Name = routeView[0]. route.StartLatitude = routeView[0].Latitude; route.StartLongitude = routeView[0].Longitude; route.EndLatitude = routeView[1].Latitude; route.EndLongitude = routeView[1].Longitude; if (routeId == 0) db.Route.Add(route); //routeId=0, add the new route db.SaveChanges(); //Delete previous way points var linqWayPoint = from wp in db.RouteWayPoint where wp.RouteId == route.RouteId select wp; // wayPoint; // = new RouteWayPoint(); foreach ( RouteWayPoint wayPoint in linqWayPoint ) { db.RouteWayPoint.Remove(wayPoint); } for (int i=2; i<routeView.Length; i++) { routeView[i].LineId -= 2; db.RouteWayPoint.Add(new RouteWayPoint(routeView[i])); } db.SaveChanges(); //return RedirectToAction("ListMobile", "Route", new { userId = Session["userId"] }); //View(CreateUpdate(route.Id)); return route.RouteId.ToString(); //Mobile?userId=" + Session["userId"]; }
public ActionResult SetRoute(RouteWayPointView[] routeView) { return View("SearchAll"); }