public ActionResult LikePost(FormCollection collection) { if (!User.Identity.IsAuthenticated) { return(Json("{\"Error\": \"Bad Authentication\",\"Code\": 1}")); } AspNetUsers user = UserService.GetUserByEmail(User.Identity.Name); post_likes likeToInsert = new post_likes(); likeToInsert.FK_group_post_like_users = user.Id; likeToInsert.FK_group_post_likes_group_posts = Convert.ToInt32(collection["postId"]); likeToInsert.post_burst = false; likeToInsert.post_like = true; try { int likeCount = PostService.SaveLikePost(likeToInsert); return(Json(likeCount)); } catch (Exception) { return(Json("{\"Error\": \"Couldn't Insert Into Database\",\"Code\": 2}")); } }
/* <summary> * Creates a like or a burst into the database depending on the values in the parameter * </summary> * <param name="postLike">post_likes object, either with the burst or like value set as 1</param> * <returns>Nothing</returns> * <author>Janus</author> */ static public int SaveLikePost(post_likes postLike) { var db = new VERK2015_H17Entities1(); int allowUserToLike = (from x in db.post_likes.Where(y => y.FK_group_post_like_users == postLike.FK_group_post_like_users && y.FK_group_post_likes_group_posts == postLike.FK_group_post_likes_group_posts && y.post_like == true) select x).Count(); if (allowUserToLike == 0) { db.post_likes.Add(postLike); db.SaveChanges(); } int totalPostLikes = (from x in db.post_likes.Where(y => y.FK_group_post_likes_group_posts == postLike.FK_group_post_likes_group_posts && y.post_like == true) select x).Count(); return(totalPostLikes); }
/* <summary>Counts the burst on the bubble</summary> * <param name="burst">Post like model</param> * <returns>The number of bubble bursts</returns> * <author>Sveinbjorn</author> */ static public int SaveBurstPost(post_likes burst) { var db = new VERK2015_H17Entities1(); int allowUserToBurst = (from x in db.post_likes.Where(y => y.FK_group_post_like_users == burst.FK_group_post_like_users && y.FK_group_post_likes_group_posts == burst.FK_group_post_likes_group_posts && y.post_burst == true) select x).Count(); if (allowUserToBurst == 0) { db.post_likes.Add(burst); db.SaveChanges(); } var burstCount = (from x in db.post_likes.Where(y => y.FK_group_post_likes_group_posts == burst.FK_group_post_likes_group_posts && y.post_burst == true) select x).Count(); return(burstCount); }