public void NewUserCoord(UserCoord userCoord) { if (userCoord != null) { userCoord.UserID = CurrentUser.Id; Context.UserCoords.Add(userCoord); Context.SaveChanges(); } }
public ActionResult SaveUserCoord(UserCoordJson userCoord) { if (userCoord != null) { try { if (userCoord.Timestamp > 0) { DateTime coordDate = new DateTime(0001, 1, 1, 0, 0, 0); DateTime.TryParse(userCoord.CreatedDate, out coordDate); //string dateformat = "yyyy-MM-dd h:mm:ss"; //DateTime.TryParseExact(userCoord.CreatedDate, dateformat, null, System.Globalization.DateTimeStyles.AssumeLocal, out coordDate); if (coordDate.Year > 1) { using (var context = new GeoLocateDataContext()) { UserCoord usrCoord = new UserCoord() { Accuracy = userCoord.Accuracy, Altitude = userCoord.Alt, Heading = userCoord.Heading, Latitude = userCoord.Lat, Longitude = userCoord.Long, Speed = userCoord.Speed, Timestamp = coordDate }; context.NewUserCoord(usrCoord); // Update Session List List <UserCoord> currentList = CurrentRouteList; if (currentList == null) { currentList = new List <UserCoord>(); } currentList.Add(usrCoord); CurrentRouteList = currentList; } } } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); ModelState.AddModelError("", ex.ToString()); } } return(View()); }// ActionResult SaveUserCoord(UserCoordJson userCoord)
public ActionResult RoutePoints(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AppExtension.NumberDecimalSeparatorChange("."); UserCoord model = new UserCoord(); try { using (var context = new GeoLocateDataContext()) { var qUserCoords = context.GetUserRoutePoints(id.Value); if (qUserCoords == null) { return(HttpNotFound()); } var routeInfo = context.GetUserRoute(id.Value); if (routeInfo != null) { ViewBag.RouteName = routeInfo.Name; ViewBag.RouteDesc = routeInfo.Description; ViewBag.RouteDate = routeInfo.Timestamp; } return(View(qUserCoords)); } // GeoLocateDataContext } catch (Exception ex) { Debug.WriteLine(ex.ToString()); ModelState.AddModelError("", ex.ToString()); } return(View(model)); }