Example #1
0
        public async Task <ActionResult <ChildCommentDto> > CreateChildComment([FromRoute] int commentId,
                                                                               [FromBody] ChildCommentDto newChildComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var parentComment = await _context.Comments
                                .Where(o => o.Id == commentId)
                                .Include(o => o.ChildComments)
                                .FirstOrDefaultAsync();

            if (parentComment == null)
            {
                return(BadRequest("Comment not found."));
            }

            var comment = new ChildComment
            {
                Author       = await _userManager.GetUserAsync(HttpContext.User),
                Text         = newChildComment.Text,
                CreationDate = DateTimeOffset.Now
            };

            parentComment.ChildComments.Add(comment);
            await _context.SaveChangesAsync();

            return(_mapper.Map <ChildCommentDto>(comment));
        }
Example #2
0
        public string[] ReplyDetails(ChildComment comment)
        {
            string[] commentDetails = new string[16];
            commentDetails[0]  = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(comment.User.Name); //username
            commentDetails[1]  = comment.User.Picture;                                               //imgUrl
            commentDetails[2]  = comment.DateTime.ToShortDateString();                               // datetime
            commentDetails[3]  = "gp" + comment.Id;                                                  //grandparentId
            commentDetails[4]  = "mc" + comment.Id;                                                  //maincommentid
            commentDetails[5]  = "cpr" + comment.Id;                                                 //childCommentId
            commentDetails[6]  = "cex" + comment.Id;                                                 //commentExpid
            commentDetails[7]  = "ctex" + comment.Id;                                                //ctrlExpid
            commentDetails[8]  = "ctflg" + comment.Id;                                               //ctrlFlagId
            commentDetails[9]  = "sp" + comment.Id;                                                  //shareParentId
            commentDetails[10] = "sc" + comment.Id;                                                  //shareChildId
            commentDetails[11] = "td" + comment.Id;                                                  //comText
            commentDetails[12] = "tdc" + comment.Id;                                                 //comTextdiv
            commentDetails[13] = "rpl" + comment.Id;                                                 //Reply
            commentDetails[14] = "cc1" + comment.Id;                                                 //commentControl
            commentDetails[15] = "cc2" + comment.Id;                                                 //commentMenu

            return(commentDetails);
        }