Пример #1
0
        public HttpResponseMessage CreateComment([FromBody] CommentSerializer comment)
        {
            try
            {
                var res = Entities.CommentCreate(CurrentIdentity.UserId, comment.PostId, comment.Content).FirstOrDefault();

                var resultComment = new Comment
                {
                    UserId      = res.UserId,
                    CommentId   = res.CommentId,
                    Content     = res.Content,
                    CreatedAt   = res.CreatedAt,
                    FirstName   = res.FirstName,
                    LastName    = res.LastName,
                    PostId      = res.PostId,
                    UserPicture = res.UserPicture,
                    Visible     = res.Visible
                };

                return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage
                {
                    Success = true,
                    Message = "Comment Created successfully.",
                    Data = resultComment
                }));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ResponseMessage
                {
                    Success = false,
                    Message = ex.Message
                }));
            }
        }
        public async Task AddComment(Comment comment, ModerationAnalysisReport report, KnownCommenterResponse knownCommenterResponse)
        {
            string yaml = CommentSerializer.SerializeToYaml(comment);

            var message = $"Add comment to '{comment.Slug}' by '{comment.Name}'";
            var path    = Path.Combine(_commentDataPath, comment.Slug, $"comment-{comment.Date.Ticks}.yml");
            var branch  = _branch;

            if (report.NeedsModeration)
            {
                branch = $"sc2g-{comment.Slug}-{comment.Date.Ticks}";
                await CreateNewBranch(branch);
            }

            var createFileRequest = new CreateFileRequest(message, yaml, branch);
            await _github.Repository.Content.CreateFile(_owner, _repo, path, createFileRequest);

            if (!knownCommenterResponse.IsKnownCommenter)
            {
                await CreateOrUpdateKnownCommentersFile(knownCommenterResponse, branch);
            }

            if (report.NeedsModeration)
            {
                var newPullRequest = new NewPullRequest(message, branch, _branch);
                newPullRequest.Body = report.ReasonForModeration;
                await _github.Repository.PullRequest.Create(_owner, _repo, newPullRequest);
            }
        }