public JsonResult UnlikePost(string UserId, int PostId) { AjaxPostLikedViewModel postLikedViewModel = new AjaxPostLikedViewModel(); if (ModelState.IsValid) { PostLike postLike = _db.PostLikes.Where(m => m.UserId == UserId && m.PostId == PostId).FirstOrDefault(); _db.PostLikes.Remove(postLike); _db.SaveChanges(); postLikedViewModel.Response = "Success"; postLikedViewModel.LikesHtml = _timeLine.BuildPostLikesHtml(PostId); return(Json(postLikedViewModel)); } else { postLikedViewModel.Response = "Failed"; return(Json(postLikedViewModel)); } }
public JsonResult LikePost(string UserId, int PostId) { AjaxPostLikedViewModel postLikedViewModel = new AjaxPostLikedViewModel(); if (ModelState.IsValid) { PostLike postLike = new PostLike { UserId = UserId, PostId = PostId }; _db.PostLikes.Add(postLike); _db.SaveChanges(); postLikedViewModel.Response = "Success"; postLikedViewModel.LikesHtml = _timeLine.BuildPostLikesHtml(PostId); return(Json(postLikedViewModel)); } else { postLikedViewModel.Response = "Failed"; return(Json(postLikedViewModel)); } }