public ActionResult RemoveAvoidanceRoute(AvoidanceRouteViewModel routeToRemove) { AvoidanceRoute removal = db.AvoidanceRoutes.Find(routeToRemove.id); db.AvoidanceRoutes.Remove(removal); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AddCustomAvoidance(AvoidanceRouteViewModel newRoute) { AvoidanceRoute routeToAdd = new AvoidanceRoute(); string userId = User.Identity.GetUserId(); Observer observer = db.Observers.Where(o => o.ApplicationUserId == userId).FirstOrDefault(); newRoute.id = int.Parse(newRoute.ObserveeId); Observee observee = db.Observees.Where(o => o.id == newRoute.id).FirstOrDefault(); float NWLong; float NWLat; float SELong; float SELat; float startlat = newRoute.BottomRightLatitude; float startlong = newRoute.BottomRightLongitude; float stoplat = newRoute.TopLeftLatitude; float stoplong = newRoute.TopLeftLongitude; if (startlat < stoplat && startlong < stoplong) { NWLat = stoplat; NWLong = startlong; SELat = startlat; SELong = stoplong; } else if (startlat > stoplat && startlong < stoplong) { NWLat = startlat; NWLong = startlong; SELat = stoplat; SELong = stoplong; } else if (startlat > stoplat && startlong > stoplong) { NWLat = startlat; NWLong = stoplong; SELat = stoplat; SELong = startlong; } else { NWLat = stoplat; NWLong = stoplong; SELat = startlat; SELong = startlong; } routeToAdd.BottomRightLatitude = SELat; routeToAdd.BottomRightLongitude = SELong; routeToAdd.TopLeftLatitude = NWLat; routeToAdd.TopLeftLongitude = NWLong; routeToAdd.Reason = newRoute.Reason; routeToAdd.RouteName = newRoute.Name; routeToAdd.ObserveeId = observee.id; routeToAdd.ObserverId = observer.id; db.AvoidanceRoutes.Add(routeToAdd); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult ViewAvoidanceRoute(AvoidanceRouteViewModel routeToFind) { string userId = User.Identity.GetUserId(); Observer observer = db.Observers.Where(o => o.ApplicationUserId == userId).FirstOrDefault(); routeToFind.RouteNames = new SelectList(db.AvoidanceRoutes.Where(r => r.ObserverId == observer.id).ToList(), "id", "RouteName"); if (routeToFind.id == null) { return(View(routeToFind)); } AvoidanceRoute foundRoute = db.AvoidanceRoutes.Where(r => r.id == routeToFind.id).FirstOrDefault(); routeToFind.Reason = foundRoute.Reason; routeToFind.BottomRightLatitude = foundRoute.BottomRightLatitude; routeToFind.BottomRightLongitude = foundRoute.BottomRightLongitude; routeToFind.TopLeftLatitude = foundRoute.TopLeftLatitude; routeToFind.TopLeftLongitude = foundRoute.TopLeftLongitude; return(View(routeToFind)); }