public void TestFavoriteWorkoutsControllerAddWorkoutToFavorites()
 {
     user_favorite_workout favWorkout = new user_favorite_workout();
     db.Setup(c => c.user_favorite_workout.Add(favWorkout)).Returns(favWorkout);
     RedirectToRouteResult result = controller.AddWorkoutToFavorites(1) as RedirectToRouteResult;
     Assert.IsNotNull(result);
     Assert.AreEqual("Index", result.RouteValues["action"], "action was not Index");
     Assert.AreEqual("FavoriteWorkouts", result.RouteValues["controller"], "controller was not FavoriteWorkouts");
 }
        public ActionResult AddWorkoutToFavorites(int? workout_id)
        {
            if (workout_id == null)
            {
                return View("DetailedError", new HttpStatusCodeResult(HttpStatusCode.BadRequest, "No workout id was specified."));
            }

            int userID = userAccess.getUserId(User.Identity.Name);
            if (userID == -1)
            {
                return View();
            }

            user_favorite_workout fav_workout = new user_favorite_workout();
            fav_workout.user_id = userID;
            fav_workout.workout_id = (int)workout_id;

            if (ModelState.IsValid)
            {
                try
                {
                    db.user_favorite_workout.Add(fav_workout);
                    db.SaveChanges();
                    if (this.Request.UrlReferrer != null)
                    {
                        string url = this.Request.UrlReferrer.PathAndQuery;
                        return Redirect(url);
                    }
                    else
                    {
                        return RedirectToAction("Index", "FavoriteWorkouts");
                    }

                }
                catch (Exception ex)
                {
                    return View("DetailedError", new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Failed to add the requested workout to favorites."));
                }
            }
            else
            {
                return View("DetailedError", new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Failed to add the requested workout to favorites."));
            }
        }
Example #3
0
 private List<user_favorite_workout> getSeedUserFavWorkouts()
 {
     var users = getSeedUsers();
     var workouts = getSeedWorkouts();
     user_favorite_workout fav1 = new user_favorite_workout
     {
         id = 1,
         user_id = 3,
         user = users[1],
         workout = workouts[0],
         workout_id = 1,
         timestamp = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0}
     };
     user_favorite_workout fav2 = new user_favorite_workout
     {
         id = 2,
         user_id = 3,
         user = users[1],
         workout = workouts[1],
         workout_id = 2,
         timestamp = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }
     };
     user_favorite_workout fav3 = new user_favorite_workout
     {
         id = 3,
         user_id = 3,
         user = users[1],
         workout = workouts[10],
         workout_id = 11,
         timestamp = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }
     };
     user_favorite_workout fav4 = new user_favorite_workout
     {
         id = 4,
         user_id = 3,
         user = users[1],
         workout = workouts[11],
         workout_id = 12,
         timestamp = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }
     };
     var userFavs = new List<user_favorite_workout> { fav1, fav2, fav3, fav4 };
     return userFavs;
 }