Exemple #1
0
        public void DeleteComment(int commentId)
        {
            Comment comment = commentRepo.ById(commentId); // Get comment by CommentId

            if (comment.ProfileId == currentProfile.id)    // validate user ownership of comment
            {
                List <Like> likes = new List <Like>();     // prepare list

                // get likes belonging to this comment
                // (type 2 is comment likes)
                foreach (Like l in likeRepo.ByTypeAndId(2, commentId))
                {
                    likes.Add(l);
                }

                // after retrieve operation, delete each retrieved like
                foreach (Like l in likes)
                {
                    likeRepo.DeleteLike(l);
                }

                // delete comment retrieved by CommentId
                commentRepo.DeleteComment(commentRepo.ById(commentId));
            }
        }