public ActionResult Login(Login login, string ReturnUrl = "")
        {
            using (db)
            {
                string hashedPassword = Hasher.HashPassword(login.Username, login.Password);
                var user = db.users.Where(a => a.username.Equals(login.Username) && a.password.Equals(hashedPassword)).FirstOrDefault();

                ModelState.Remove("Password");
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(user.username, login.RememberMe);

                    var recommender = new Recommender(this.db);
                    workout recommendation = recommender.Recommend(user.id);
                    if (Session != null && recommendation != null) Session["recommendedId"] = recommendation.id;

                    if (user.is_admin == 1)
                    {
                        return RedirectToAction("Index", "AdminHome");
                    }
                    //ReturnUrl = Request.QueryString["ReturnURL"];

                    if (!string.IsNullOrEmpty(ReturnUrl) && Url.IsLocalUrl(ReturnUrl))
                    {
                        return Redirect(ReturnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "MyProfile");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            return View();
        }
 /// <summary>
 /// Gets the recommended workout id from the session if it exists
 /// </summary>
 private void setRecommendedWorkout(int id)
 {
     if (Session != null)
     {
         workout recWorkout = null;
         var recommendedId = Session["recommendedId"];
         if (recommendedId != null)
         {
             recWorkout = db.workouts.Find(recommendedId);
             Session["recommendedId"] = recWorkout.id;
         }
         else if (id > 0)
         {
             var recommender = new Recommender(this.db);
             recWorkout = recommender.Recommend(id);
             if (recWorkout != null) Session["recommendedId"] = recWorkout.id;
         }
         ViewBag.recommended = recWorkout;
     }
 }
 public void Initialize()
 {
     DbContextHelpers contextHelpers = new DbContextHelpers();
     db = contextHelpers.getDbContext();
     recommender = new Recommender(db.Object);
 }