public ActionResult Like(LikeModel like) { var id = User.Identity.GetUserId(); var l = db.FindLike(id, like.RecipeId); if (l != null) { if (l.Value == 0) { l.Value = 1; } else { l.Value = 0; } var val = l.Value; db.UpdateLike(l); db.Save(); return(RedirectToAction("Details", "Recipe", new { id = like.RecipeId })); } else { var likeToAdd = new Like() { Id = 1, UserId = User.Identity.GetUserId(), RecipeId = like.RecipeId, Value = 1 }; db.AddLike(likeToAdd); db.Save(); return(RedirectToAction("Details", "Recipe", new { id = like.RecipeId })); } }