Exemple #1
0
        public static bool UnlikePost(long postId, string userId)
        {
            using (var context = new BackofficeUnitOfWork())
            {
                PostLike like = context.PostLike.First(i => i.ID_Post == postId && i.ID_User == userId);

                if (null == like)
                {
                    return(false);
                }

                context.PostLike.Delete(like.ID);
                context.Save();

                return(true);
            }
        }
Exemple #2
0
        public static bool LikePost(long postId, string userId)
        {
            using (var context = new BackofficeUnitOfWork())
            {
                if (context.PostLike.Fetch().Count(i => i.ID_Post == postId && i.ID_User == userId) > 0)
                {
                    return(false);
                }

                PostLike like = new PostLike()
                {
                    Active      = true,
                    AspNetUsers = context.AspNetUsers.Get(userId),
                    Date        = DateTime.Now,
                    Post        = context.Post.Get(postId)
                };

                context.PostLike.Create(like);
                context.Save();

                return(like.ID > 0);
            }
        }