Exemplo n.º 1
0
        public IActionResult PublishComment([FromBody] CommentAddModel model)
        {
            CommentAddReturnModel ret = new CommentAddReturnModel();

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            Claim idClaim    = User.FindFirst("sub");
            Claim unameClaim = User.FindFirst("nickname");

            if (idClaim == null)
            {
                return(StatusCode(401));
            }
            else
            {
                ret = _commentActionService.PublishComment(model.Content, idClaim.Value, model.ReviewId);
                if (ret.IsActionSucceed)
                {
                    ret.Comment.UserInfo.UserName = unameClaim.Value;
                    _bus.Publish <UserAddedCommentAction>(new UserAddedCommentAction()
                    {
                        DateUtcAction  = DateTime.UtcNow,
                        CommentId      = ret.Comment.Id,
                        ReviewId       = model.ReviewId,
                        UserId         = idClaim.Value,
                        ReviewAuthorId = ret.ReviewAuthorId,
                        Username       = unameClaim.Value,
                        PostId         = ret.PostId
                    });
                }
            }
            return(Ok(ret));
        }
Exemplo n.º 2
0
        public async Task <StatusModel> CommentAdd(CommentAddModel amodel)
        {
            StringBuilder strTxt = new StringBuilder();

            BLL.article_comment   bll   = new BLL.article_comment();
            Model.article_comment model = new Model.article_comment();

            if (amodel.articleId == 0)
            {
                return(new StatusModel {
                    status = 0, msg = "对不起,参数传输有误!"
                });
            }
            if (string.IsNullOrEmpty(amodel.content))
            {
                return(new StatusModel()
                {
                    status = 0, msg = "对不起,请输入评论的内容!"
                });
            }
            //检查该文章是否存在
            Model.article artModel = new BLL.article().GetModel(amodel.articleId);
            if (artModel == null)
            {
                return(new StatusModel()
                {
                    status = 0, msg = "对不起,主题不存在或已删除!"
                });
            }
            //检查用户是否登录
            int    user_id   = 0;
            string user_name = "匿名用户";
            var    user      = await UserManager.FindByIdAsync(int.Parse(User.Identity.GetUserId()));

            if (user != null)
            {
                user_id   = user.id;
                user_name = user.user_name;
            }
            model.channel_id = artModel.channel_id;
            model.article_id = artModel.id;
            model.content    = Utils.ToHtml(amodel.content);
            model.user_id    = user_id;
            model.user_name  = user_name;
            model.user_ip    = DTRequest.GetIP();
            model.is_lock    = siteConfig.commentstatus; //审核开关
            model.add_time   = DateTime.Now;
            model.is_reply   = 0;
            if (bll.Add(model) > 0)
            {
                return(new StatusModel()
                {
                    status = 1, msg = "留言提交成功!"
                });
            }
            return(new StatusModel()
            {
                status = 0, msg = "对不起,保存过程中发生错误!"
            });
        }
Exemplo n.º 3
0
        public async Task AddCommentAsync(CommentAddModel model)
        {
            var jsonData = JsonConvert.SerializeObject(model);
            var content  = new StringContent(jsonData, Encoding.UTF8, "application/json");

            await _httpClient.PostAsync("AddComment", content);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            // if model is valid then process
            if (ModelState.IsValid)
            {
                var mode = "edit";

                // if this is a revision to an existing comment then add revision
                if (CommentEditModel.Id.HasValue)
                {
                    RevisionAddModel model = new RevisionAddModel
                    {
                        CommentHeaderId = CommentEditModel.Id.Value,
                        Text            = CommentEditModel.NewText
                    };
                    await _service.AddRevisionAsync(model);
                }
                // Else add comment - need current user id
                else
                {
                    mode = "add";
                    CommentAddModel model = new CommentAddModel
                    {
                        UserId = User.FindFirstValue(ClaimTypes.NameIdentifier),
                        Text   = CommentEditModel.NewText
                    };
                    await _service.AddCommentAsync(model);
                }

                StatusMessage = string.Format("Comment {0}ed successfully", mode);
                return(RedirectToPage("Index"));
            }
            // else redisplay page - validation errors will be displayed
            return(Page());
        }
Exemplo n.º 5
0
        public async Task SaveComment(CommentAddModel commentModel)
        {
            USER user = await _userRepository.GetUserByContext(HttpContext.User);

            if (_teamRepository.IsTeamMember(user, commentModel.TeamId) && _permissionService.CheckPermissionToCommentTasks(user, commentModel.TeamId))
            {
                _taskService.AddCommentToTask(commentModel, user);
            }
        }
        public async Task <IResultModel> Add(CommentAddModel model)
        {
            var entity = _mapper.Map <CommentEntity>(model);
            //if (await _repository.Exists(entity))
            //{
            //return ResultModel.HasExists;
            //}

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
Exemplo n.º 7
0
        public ActionResult AddNewComment(CommentAddModel model)
        {
            if (model != null && !string.IsNullOrEmpty(model.Text) && model.Text.Trim().Length > 1000)
            {
                return(new JsonResult()
                {
                    Data = new { result = "maxLenghtError", validator = "NewComment", message = "Максимальная длина комментария 1000 символов" }
                });
            }

            if (model != null && model.AuthorId != 0 && model.TaskId != 0 && !string.IsNullOrEmpty(model.Text))
            {
                try
                {
                    using (var context = new TaskManagerContext())
                    {
                        var task = context.Tasks.Include(x => x.Comments).FirstOrDefault(x => x.TaskId == model.TaskId);
                        if (task != null)
                        {
                            task.Comments.Add(new Comment
                            {
                                AuthorId    = model.AuthorId,
                                CommentText = model.Text.Trim(),
                                CommentDate = DateTime.Now
                            });
                            context.SaveChanges();
                            return(new JsonResult()
                            {
                                Data = new { result = "success" }
                            });
                        }
                    }
                }
                catch (DbEntityValidationException ex)
                {
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
            }
            return(new JsonResult()
            {
                Data = new { result = "error" }
            });
        }
        public void PostComment_Should_ReturnCommentModel()
        {
            var photoId      = 1;
            var commentModel = new CommentAddModel {
                Text = "text"
            };
            var commentDTO = new CommentDTO {
                Text = "text"
            };

            mockService.Setup(s => s.AddCommentAsync(It.Is <CommentAddDTO>(dto =>
                                                                           dto.Text == commentModel.Text))).ReturnsAsync(commentDTO).Verifiable();

            controller.PostComment(photoId, commentModel).Result.Result.Should().BeOfType <OkObjectResult>()
            .Which.Value.Should().BeEquivalentTo(commentModel);
            mockService.Verify();
        }
Exemplo n.º 9
0
        public void AddCommentToTask(CommentAddModel commentModel, USER user)
        {
            TASK task = _taskRepository.GetTaskById(commentModel.TaskId);

            if (task != null)
            {
                COMMENT comment = new COMMENT
                {
                    CONTENT = commentModel.CommentContent,
                    CREATED = DateTime.Now,
                    TASK    = task,
                    USER    = user
                };

                _commentRepository.AddComment(comment);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Task for adding a comment
        /// </summary>
        /// <param name="model">The comment to add</param>
        /// <returns>Task for adding a comment</returns>
        public async Task AddCommentAsync(CommentAddModel model)
        {
            CommentHeader header = new CommentHeader
            {
                UserId           = model.UserId,
                CommentRevisions = new CommentRevision[]
                {
                    new CommentRevision
                    {
                        CreatedDate = DateTime.UtcNow,
                        Text        = model.Text
                    }
                }
            };

            _context.CommentHeaders.Add(header);
            await _context.SaveChangesAsync();
        }
Exemplo n.º 11
0
        public async Task <IActionResult> AddToComment(CommentAddModel model)
        {
            await _blogApiService.AddToCommentAsync(model);

            return(RedirectToAction("BlogDetail", new { id = model.BlogId }));
        }
Exemplo n.º 12
0
        public async Task <ActionResult> AddComment(CommentAddModel model)
        {
            var userId = User.Identity.GetUserId();

            if (string.IsNullOrEmpty(userId))
            {
                return(Json(Js.Error("Vui lòng đăng nhập để thảo luận")));
            }
            ;

            var user = db.Users.Find(userId);

            if (user == null)
            {
                return(Json(Js.Error("Vui lòng đăng nhập để thảo luận")));
            }
            ;


            var blog = await db.Blogs.FindAsync(model.BlogId);

            if (blog == null)
            {
                return(Json(Js.Error("Không tìm thấy bài viết")));
            }
            ;

            if (blog.Closed)
            {
                return(Json(Js.Error("Thảo luận cho bài viết đã đóng")));
            }
            ;

            if (model.ParentId != null)
            {
                var parent = db.Comments.Find(model.ParentId);
                if (parent == null)
                {
                    return(Json(Js.Error("Không tìm thấy thảo luận")));
                }
                ;
            }
            var content = await model.Content.GetValidHtml();

            if (string.IsNullOrEmpty(content))
            {
                return(Json(Js.Error("Nội dung không được để trống")));;
            }
            var data = new Comment(new DBHelper().GetCommentId(db), content)
            {
                UserId = user.Id,
                BlogId = model.BlogId,
                AppId  = model.AppId
            };

            if (model.ParentId != null)
            {
                data.ParentId = model.ParentId;
            }
            db.Comments.Add(data);
            db.SaveChanges();
            return(Json(Js.SuccessComponent("Đã đăng thảo luận", "comments-container")));;
        }
Exemplo n.º 13
0
 public Task <IResultModel> Add(CommentAddModel model)
 {
     return(_service.Add(model));
 }
Exemplo n.º 14
0
        public async Task <IActionResult> AddComment(CommentAddModel model)
        {
            await _topicApiService.AddToComment(model);

            return(RedirectToAction("TopicDetail", new { id = model.TopicId }));
        }
Exemplo n.º 15
0
        public async Task <ActionResult <CommentModel> > PostComment([FromRoute] int photoId, [FromBody] CommentAddModel commentAddModel)
        {
            var commentAddDTO = mapper.Map <CommentAddDTO>(commentAddModel,
                                                           opt => { opt.Items["photoId"] = photoId; opt.Items["userId"] = UserId; });

            return(Ok(mapper.Map <CommentDTO>(await commentService.AddCommentAsync(commentAddDTO))));
        }
Exemplo n.º 16
0
 public Task <IResultModel> Create(CommentAddModel model)
 {
     //model = CreatedIP
     return(_service.Add(model));
 }