示例#1
0
        public async Task <Comment> Create_CommentAsync([FromBody] InsertComment comment)
        {
            Comment c = new Comment();

            if (ModelState.IsValid)
            {
                Owner  owner                  = um.GetUser_Cookie(Request);
                string decoded_post_id        = _helper.DecodeFrom64(comment.post_id);
                PostParticipantManagement ppm = new PostParticipantManagement();
                if (comment.sub_post_id != null)
                {
                    decoded_post_id = _helper.DecodeFrom64(comment.sub_post_id);
                    await ppm.send_email_to_participant_sub_post_comment(_helper.DecodeFrom64(comment.post_id), decoded_post_id, owner, 0);

                    await pm.increase_sub_post_comment_countAsync(_helper.DecodeFrom64(comment.post_id), decoded_post_id, 1);
                }
                else
                {
                    await ppm.send_email_to_participant_post_comment(decoded_post_id, owner, 0);

                    await pm.increase_commentsAsync(decoded_post_id, 1);
                }
                c = await cm.insertComment(decoded_post_id, new Comment
                {
                    message      = comment.comment_text,
                    date_created = DateTime.Now,
                    owner        = owner
                });

                c._id      = _helper.EncodeTo64(c._id);
                c.has_like = "none";
                c.is_own   = true;
                MailManager mm = new MailManager();
                if (!ppm.has_participated(decoded_post_id, owner._id))
                {
                    await ppm.insertPostParticipantRecord(decoded_post_id, new Participant { _id = owner._id, email = owner.email, status = true });
                }
            }
            return(c);
        }