Example #1
0
        public ActionResult SaveFavoriteRoute(SaveFavoriteRouteViewModel saveFavoriteRouteViewModel)
        {
            if (saveFavoriteRouteViewModel == null) // TODO - Is this nescessary? I don't think so.
            {
                throw new ArgumentNullException(nameof(saveFavoriteRouteViewModel));
            }

            if (HttpContext.Session.GetString("_Email") is null) // TODO - Is there a better way to filter this?
            {
                return(Redirect("/User/LogOn"));
            }
            else
            {
                //TODO - Form DB relationship between User and Route.
                int userId  = saveFavoriteRouteViewModel.UserID;
                int routeId = saveFavoriteRouteViewModel.RouteID;
                IList <UserRoute> existingItems = context.UserRoutes
                                                  .Where(ur => ur.UserID == userId)
                                                  .Where(ur => ur.RouteID == routeId).ToList();
                if (existingItems.Count == 0)
                {
                    //var userID = saveFavoriteRouteViewModel.UserID;
                    //var routeID = saveFavoriteRouteViewModel.RouteID;
                    try {
                        UserRoute favRoute = new UserRoute
                        {
                            User  = context.Users.Single(u => u.ID == userId),
                            Route = context.Routes.Single(r => r.ID == routeId)
                        };
                        context.UserRoutes.Add(favRoute);
                        context.SaveChanges();

                        TempData["Alert"] = "The Ride Route has been added to Your Favorites!";

                        return(Redirect("/User/DisplayFavorites"));
                    }
                    catch // TODO - I made it try catch this for some reason...
                    {
                        UserRoute favRoute = new UserRoute
                        {
                            User  = context.Users.Single(u => u.ID == userId),
                            Route = context.Routes.Single(r => r.ID == routeId)
                        };
                        context.UserRoutes.Add(favRoute);
                        context.SaveChanges();

                        TempData["Alert"] = "The Ride Route has been added to Your Favorites!";

                        return(Redirect("/User/DisplayFavorites"));
                    }
                }
            }
            return(Redirect("/User/DisplayFavorites"));
        }
Example #2
0
        public ActionResult EnterReview(SaveFavoriteRouteViewModel saveFavoriteRouteViewModel)
        {
            if (HttpContext.Session.GetString("_Email") is null) // TODO - Is there a better way to filter this?
            {
                return(Redirect("/User/LogOn"));
            }

            string apiKey = string.IsNullOrEmpty(this._secrets.MySecret) // ViewData "object" not a string, doesn't work in pass to View, must use ViewBag?
                ? "Are you in production?"
                : this._secrets.MySecret;
            Route theRoute = context.Routes.Single(r => r.ID == saveFavoriteRouteViewModel.RouteID);
            User  user     = context.Users.Single(u => u.ID == saveFavoriteRouteViewModel.UserID);

            ViewBag.RouteID        = theRoute.ID;
            ViewBag.MapUrl         = string.Format("https://www.google.com/maps/embed/v1/directions?origin={0} &waypoints={1} &destination={2} &key={3}", theRoute.Origin, theRoute.Waypoints, theRoute.Destination, apiKey);
            ViewBag.UserScreenName = HttpContext.Session.GetString("_ScreenName");
            return(View());
        }