Example #1
0
        public async Task <bool> CommentVoting(CommentVoting commentVoting)
        {
            try
            {
                var upateCommentVoting = await db.CommentVotings
                                         .FirstOrDefaultAsync(d =>
                                                              d.UserId == commentVoting.UserId &&
                                                              d.CommentId == commentVoting.CommentId
                                                              );

                if (upateCommentVoting != null)
                {
                    commentVoting.UpdatedDate     = DateTime.Now;
                    upateCommentVoting.VotingType = commentVoting.VotingType;
                    await db.SaveChangesAsync();

                    return(true);
                }

                commentVoting.CreatedDate = DateTime.Now;
                db.CommentVotings.Add(commentVoting);
                await db.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #2
0
        public async Task <ActionResult> CommentVotting([FromBody] CommentVoting model)
        {
            var currentUser = CurrentLoginUser;

            if (currentUser == null)
            {
                return(Ok(new { IsSuccess = false, Message = "There was an error while trying to like/dislike this comment" }));
            }

            //let's register the class
            var isVoted = await _postService.CommentVoting(model);

            if (!isVoted)
            {
                return(Ok(new { IsSuccess = false, Message = "There was an error while trying to like/dislike this comment!" }));
            }

            return(Ok(new { IsSuccess = true, Message = "successful" }));
        }
 /// <summary>
 /// Create a new CommentVoting object.
 /// </summary>
 /// <param name="commentVotingID">Initial value of CommentVotingID.</param>
 /// <param name="rating">Initial value of Rating.</param>
 public static CommentVoting CreateCommentVoting(int commentVotingID, int rating)
 {
     CommentVoting commentVoting = new CommentVoting();
     commentVoting.CommentVotingID = commentVotingID;
     commentVoting.Rating = rating;
     return commentVoting;
 }
 /// <summary>
 /// There are no comments for CommentVoting in the schema.
 /// </summary>
 public void AddToCommentVoting(CommentVoting commentVoting)
 {
     base.AddObject("CommentVoting", commentVoting);
 }