Ejemplo n.º 1
0
        private static Response LikeCommentResponse(LikeComment likeComment)
        {
            DatabaseManager database = new DatabaseManager();
            string          query    = "";

            if (likeComment.LikeDislike > 0)
            {
                query = $"UPDATE comments SET likes=likes+1 WHERE uid = '{likeComment.CommentID}'";
            }
            else
            {
                query = $"UPDATE comments SET dislikes=dislikes+1 WHERE uid = '{likeComment.CommentID}'";
            }
            (MySqlDataReader reader, var Connection) = database.RunQuery(query);
            Acknowledge ack = new Acknowledge()
            {
                Status = "OK", Reason = "Liked"
            };
            Response resp = new Response()
            {
                Type = ResponseType.Acknowledge, Status = "OK", Content = ack
            };

            if (reader == null)
            {
                ack.Reason = "Unable to like";
                ack.Status = "FAIL";
            }
            Connection.Close();
            return(resp);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Like([FromBody] LikeComment like)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            like.LikeTime = DateTime.Now;

            _context.LikeComment.Add(like);
            await _context.SaveChangesAsync();

            return(Ok("You liked the comment"));
        }
Ejemplo n.º 3
0
        public void AddLikeComment(string userName, int commentID)
        {
            if (GetUserByUserName(userName) == null || GetCommentById(commentID) == null)
            {
                return;
            }

            LikeComment likeComment = new LikeComment();

            likeComment.ApplicationUser = GetUserByUserName(userName);
            likeComment.Comment         = GetCommentById(commentID);

            dbContext.LikeComments.Add(likeComment);
            dbContext.SaveChanges();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// อัพเดทหรือเพิ่มข้อมูล like lesson
        /// </summary>
        /// <param name="data">ข้อมูลที่ต้องการดำเนินการ</param>
        public void UpsertLikeComment(LikeComment data)
        {
            var update = Builders <LikeComment> .Update
                         .Set(it => it.ClassRoomId, data.ClassRoomId)
                         .Set(it => it.CommentId, data.CommentId)
                         .Set(it => it.LessonId, data.LessonId)
                         .Set(it => it.LikedByUserProfileId, data.LikedByUserProfileId)
                         .Set(it => it.LastNotifyRequest, data.LastNotifyRequest)
                         .Set(it => it.LastNotifyComplete, data.LastNotifyComplete)
                         .Set(it => it.CreatedDate, data.CreatedDate)
                         .Set(it => it.DeletedDate, data.DeletedDate);

            var updateOption = new UpdateOptions {
                IsUpsert = true
            };

            MongoAccess.MongoUtil.Instance.GetCollection <LikeComment>(TableName)
            .UpdateOne(it => it.id == data.id, update, updateOption);
        }
Ejemplo n.º 5
0
        public IActionResult Like(string UserID, string CommentID)
        {
            //首先查找是否有现有的点赞
            var like    = Cservice.GetLike(UserID, CommentID);
            var comment = Cservice.GetComment(CommentID);

            //该用户已经赞了这个评论
            if (like != null)
            {
                //取消赞
                context.LikeComment.Remove(like);
                comment.total_like--;
                context.Comment.Attach(comment);
                context.SaveChanges();

                return(Ok(new
                {
                    Success = true,
                    msg = "DisLiked"
                }));
            }
            //创建新的赞
            else
            {
                like = new LikeComment
                {
                    c_id = CommentID,
                    u_id = UserID
                };

                context.LikeComment.Add(like);
                comment.total_like = +1;
                context.Attach(comment);
                context.SaveChanges();

                return(Ok(new
                {
                    Success = true,
                    msg = "Liked"
                }));
            }
        }
Ejemplo n.º 6
0
        private async void LikeDislikeButton_Click(object sender, RoutedEventArgs e)
        {
            int         likeDislike = int.Parse(((Button)sender).Tag.ToString());
            LikeComment request     = new LikeComment()
            {
                LikeDislike = likeDislike, UserID = SettingsManager.Username, CommentID = Comment.Uid
            };
            Object response = await ConnectionManager.SendRequestAsync(request, RequestType.LikeComment, ResponseType.Acknowledge);

            if (response != null)
            {
                if (((JObject)response).ToObject <Acknowledge>().Status == "OK")
                {
                    if (likeDislike > 0)
                    {
                        likeTextBlock.Text = (int.Parse(likeTextBlock.Text) + 1).ToString();
                    }
                    else
                    {
                        dislikeTextBlock.Text = (int.Parse(dislikeTextBlock.Text) + 1).ToString();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void Like(LikeCommentRequest body)
        {
            var areArgumentsValid = body != null &&
                                    !string.IsNullOrEmpty(body.ClassRoomId) &&
                                    !string.IsNullOrEmpty(body.CommentId) &&
                                    !string.IsNullOrEmpty(body.LessonId) &&
                                    !string.IsNullOrEmpty(body.UserProfileId);

            if (!areArgumentsValid)
            {
                return;
            }

            var canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(body.UserProfileId, body.ClassRoomId);

            if (!canAccessToTheClassRoom)
            {
                return;
            }

            var now = _dateTime.GetCurrentTime();
            var canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(body.ClassRoomId, body.LessonId, now);

            if (!canAccessToTheClassLesson)
            {
                return;
            }

            var selectedComment = _commentRepo.GetCommentById(body.CommentId);

            if (selectedComment == null)
            {
                return;
            }

            var likeComments = _likeCommentRepo.GetLikeCommentByCommentId(body.CommentId)
                               .Where(it => !it.DeletedDate.HasValue)
                               .ToList();

            var likedCommentsByThisUser = likeComments
                                          .Where(it => it.LikedByUserProfileId.Equals(body.UserProfileId, StringComparison.CurrentCultureIgnoreCase));

            var isUnlike = likedCommentsByThisUser.Any();

            if (isUnlike)
            {
                foreach (var item in likedCommentsByThisUser)
                {
                    item.DeletedDate = now;
                    _likeCommentRepo.UpsertLikeComment(item);
                }
            }
            else
            {
                var isCommentOwner = selectedComment.CreatedByUserProfileId.Equals(body.UserProfileId, StringComparison.CurrentCultureIgnoreCase);
                if (!isCommentOwner)
                {
                    var canLikeThisComment = _userprofileRepo.CheckAccessPermissionToUserProfile(selectedComment.CreatedByUserProfileId);
                    if (!canLikeThisComment)
                    {
                        return;
                    }
                }

                var selectedUserActivity = _userActivityRepo.GetUserActivityByUserProfileIdAndClassRoomId(body.UserProfileId, body.ClassRoomId);
                if (selectedUserActivity == null)
                {
                    return;
                }
                var selectedLessonActivity = selectedUserActivity.LessonActivities.FirstOrDefault(it => it.LessonId.Equals(body.LessonId));
                if (selectedLessonActivity == null)
                {
                    return;
                }
                selectedLessonActivity.ParticipationAmount++;
                _userActivityRepo.UpsertUserActivity(selectedUserActivity);

                var newLike = new LikeComment
                {
                    id                   = Guid.NewGuid().ToString(),
                    ClassRoomId          = body.ClassRoomId,
                    LessonId             = body.LessonId,
                    CommentId            = body.CommentId,
                    LikedByUserProfileId = body.UserProfileId,
                    CreatedDate          = now
                };
                likeComments.Add(newLike);
                _likeCommentRepo.UpsertLikeComment(newLike);
            }

            selectedComment.TotalLikes = likeComments.Where(it => !it.DeletedDate.HasValue).Count();
            _commentRepo.UpsertComment(selectedComment);
            _notificationCtrl.SendNotification();
        }
Ejemplo n.º 8
0
 public BuilderLikeList(Action refresh, Form form, Panel panel, Point targetLocation, int postID, int userID, ProxyFacebook proxy)
 {
     likeComment       = new LikeComment(refresh, form, panel, targetLocation, postID, userID, proxy);
     likeComment.likes = proxy.GetLikes(postID);
 }