public ActionResult SingleProfileView(string Username) { System.Diagnostics.Debug.WriteLine(Username + " inside SPVC"); string SingleUser = Username; Profile SingleProf = new Profile(); int Likes = 0; Like likeModel = new Like(); bool LikeStat; SingleProf = ReturnProfile(SingleUser); Likes = likeModel.LikeCount(SingleUser); ViewBag.Likes = Likes; ViewBag.Profile = SingleProf; LikeStat = likeModel.LikeUnlike(Username, Session["Username"].ToString()); if (LikeStat == true) { ViewBag.LikeStat = "Like"; } else { ViewBag.LikeStat = "Unlike"; } return(View()); }
public ActionResult LikeClicked(string liked_Profile) { Like likeModel = new Like(); Profile profile = new Profile(); System.Diagnostics.Debug.WriteLine("Inside Like Post " + liked_Profile); SqlDataReader reader = null; SqlConnection cn = null; SqlCommand cmd = null; string _sql = null; bool LikeStat = true; if (Session["Username"] == null) { var UC = new UserController(); UC.Logout(); } string liked_User = Session["Username"].ToString(); try { cn = new SqlConnection(Constants.ConnString); LikeStat = likeModel.LikeUnlike(liked_Profile, liked_User); if (LikeStat == true) { //LIKES cn.Close(); _sql = @"INSERT INTO Likes (liked_user, profile_liked) VALUES (@liked_user, @profile)"; cmd = new SqlCommand(_sql, cn); cmd.Parameters.AddWithValue("@liked_user", liked_User); cmd.Parameters.AddWithValue("@profile", liked_Profile); cn.Open(); reader = cmd.ExecuteReader(); SendMailLike(liked_Profile, liked_User); } else { //UNLIKES cn.Close(); _sql = @"DELETE FROM Likes WHERE liked_user = @liked_user AND profile_liked = @profile"; cmd = new SqlCommand(_sql, cn); cmd.Parameters.AddWithValue("@liked_user", liked_User); cmd.Parameters.AddWithValue("@profile", liked_Profile); cn.Open(); reader = cmd.ExecuteReader(); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } System.Diagnostics.Debug.WriteLine(liked_User + " " + LikeStat + " " + liked_Profile); return(RedirectToAction("SingleProfileView", "Profile", new { Username = liked_Profile })); }