public override async Task Run() { var blogPostId = await _blogPostService.AddBlogPostAsync("New post!", "Hello world."); await _commentService.AddCommentAsync(blogPostId, "Commenter 1", "Nice post."); await _commentService.AddCommentAsync(blogPostId, "Commenter 2", "Nice post!"); // this instruction will not work normally since some of these methods will try to update // an entity that has changed in the mean time, failing the ETag validation await Task.WhenAll( _commentService.AddLikeAsync(blogPostId), _commentService.AddLikeAsync(blogPostId), _commentService.AddLikeAsync(blogPostId), _commentService.AddLikeAsync(blogPostId), _commentService.AddLikeAsync(blogPostId)); var blogPosts = await _blogPostService.GetBlogPostsAsync(); Console.WriteLine(JsonConvert.SerializeObject(blogPosts)); await Task.Delay(30000); blogPosts = await _blogPostService.GetBlogPostsAsync(); Console.WriteLine(JsonConvert.SerializeObject(blogPosts)); await _blogPostService.DeleteBlogPostAsync(blogPostId); }
public async Task <IActionResult> CreateComment([FromBody] CommentDto comment) { if (ModelState.IsValid) { await _commentService.AddCommentAsync(comment); return(Ok()); } return(BadRequest(ModelState)); }
public async Task <ActionResult <CommentDTO> > PostComment(int id, [FromBody] CommentAddDTO commentAddDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (commentAddDTO.PhotoId != id) { return(BadRequest()); } CommentDTO commentDTO; try { commentDTO = await _commentService.AddCommentAsync(commentAddDTO, UserId); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok(commentDTO)); }
public async Task <Comment> AddCommentAsync(string entryId, CommentRequest request) { var entry = await this.GetEntryByIdAsync(entryId); if (entry is null) { throw new RequestedResourceNotFoundException(nameof(entryId)); } var comment = await commentService.AddCommentAsync(request, entry); if (entry.Comments is null) { entry.Comments = new List <Comment>() { comment }; } else { entry.Comments.Add(comment); } var newCommentList = entry.Comments; await context.Entries.UpdateOneAsync((i) => i.Id == entry.Id, Builders <Entry> .Update .Set(j => j.Comments, newCommentList)); return(comment); }
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)))); }
public async Task <ActionResult> SaveMessage([FromBody] CommentEntity param) { // 获取IP地址 if (param.location != null) { if (Request.HttpContext.Connection.RemoteIpAddress != null) { var ip = Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); param.location = ip; } } param.createDate = DateTime.Now; param.targetId ??= 0; var flag = await _commentService.AddCommentAsync(param); // 发送邮件 if (param.targetId == 0 || param.targetUserId == null) { return(Ok(flag)); } var toComment = await _commentService.GetCommentByIdAsync(param.targetId.Value); var fromComment = await _commentService.GetCommentByIdAsync(param.id); flag = _emailHelper.ReplySendEmail(toComment, fromComment, SendEmailType.回复评论); return(Ok(flag)); }
public async Task AddCommentAsync(CommentCreateModel model) { var commentDto = _mapper.Map <CommentDTO>(model); commentDto.AppUserId = (await _currentUser.GetCurrentUser(_httpContextAccessor.HttpContext)).Id; await _commentService.AddCommentAsync(commentDto); }
public async Task <Guid> AddCommentAsync(Guid postId, SaveCommentModel model) { ArgumentGuard.NotEmpty(postId, nameof(postId)); ArgumentGuard.NotNull(model, nameof(model)); var post = await _postService.GetPostAsync(postId); // permission return(await _commentService.AddCommentAsync(post.Id, model)); }
public async Task <IActionResult> Post(CommentAddRequest request) { Outcome <int> outcome = await _commentService.AddCommentAsync(request); if (!outcome.Successful) { return(RequestError(outcome)); } return(CreatedAtAction(nameof(Get), new { commentId = outcome.Result }, null)); }
public async Task <IActionResult> AddComment([FromBody] CommentViewModel model) { if (ModelState.IsValid) { model.UserId = HttpContext.GetUserIdAsync(); CommentModel comment = _mapper.Map <CommentViewModel, CommentModel>(model); await _hubContext.Clients.All.SendAsync("GetComment", await _commentService.AddCommentAsync(comment)); return(Ok()); } return(BadRequest(ModelState)); }
public async Task <ActionResult> CreateComment(int postId, string text) { var commentVm = new CommentViewModel(); commentVm.Text = text; commentVm.User = new UserViewModel { UserName = System.Web.HttpContext.Current.User.Identity.Name }; await service.AddCommentAsync(postId, commentVm.ToDto()); return(RedirectToAction(Constant.View.GetPost, Constant.View.Post, new { postId = postId })); }
public async Task <HttpResponseMessage> Post(string projectId, CommentModel comment) { var domainComment = new DomainComment { ProjectId = projectId, UserId = UserId, Body = comment.Body, DateTime = DateTime.UtcNow }; domainComment = await _commentService.AddCommentAsync(domainComment); var avatarUrl = _userAvatarProvider.GetAvatar(new DomainUser { Email = domainComment.UserEmail }); var responseComment = _mapper.Map <Tuple <DomainComment, string>, Comment>( new Tuple <DomainComment, string>(domainComment, avatarUrl)); var project = await _projectService.GetAsync(new DomainProject { Id = domainComment.ProjectId, UserId = domainComment.OwnerId }); // Notify owner about video comments if (project.UserId != domainComment.UserId) { var videoOwner = await _userService.GetAsync(project.UserId); // Checks whether video comments notification enabled if (videoOwner.NotifyOnVideoComments) { // Send notification e-mail try { await _notificationService.SendVideoCommentNotificationAsync(videoOwner, project, domainComment); } catch (Exception e) { Trace.TraceError("Failed to send video comment notification email to address {0} for user {1}: {2}", videoOwner.Email, videoOwner.Id, e); } } } return(Request.CreateResponse(HttpStatusCode.Created, responseComment)); }
public async Task <ActionResult> SendComment(CommentModel comment) { string userID = await _userService.FindIdByUserNameAsync(User.Identity.Name); var commentDTO = new BL.DTO.CommentDTO() { User = new BL.DTO.UserDTO() { Id = userID, UserName = User.Identity.Name }, Date = DateTime.Now, ImageID = comment.ImageID, Text = comment.Text }; var sendResult = await _commentService.AddCommentAsync(commentDTO); return(sendResult.Successed ? Json(commentDTO) : null); }
public async Task <IActionResult> AddComment([FromBody] CreateCommentRequest commentRequest) { var newCommentDb = new CommentDb { Comment = commentRequest.Comment, PostId = commentRequest.PostId, Created = DateTime.Now, UserId = HttpContext.GetUserId(), }; var result = await _commentService.AddCommentAsync(newCommentDb); if (!result) { return(BadRequest("Unable to create Comment")); } return(Ok()); }
public async Task <ActionResult <IResponseModel> > PostAddCommentAsync([FromBody] CommentModel obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var isTaskAdded = await _commentService.AddCommentAsync(obj); _response.Status = isTaskAdded.Status; _response.Message = isTaskAdded.Message; if (_response.Status) { return(Ok(_response)); } else { return(BadRequest(_response)); } }
public async Task <IActionResult> AddComment([FromBody] JObject jObject) { string forum_id = jObject["forum_id"].ToString(); string Content = jObject["content"].ToString(); if (string.IsNullOrEmpty(forum_id) || string.IsNullOrWhiteSpace(Content)) { return(Json(new { code = "400", message = "格式错误" })); } //获取用户ID string phone = HttpContext.User.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.OtherPhone).Value; string user_id = _accountService.GetUserID(phone); Forum forum = null; if (!await _forumSerivce.isExistAsync(forum_id)) { return(Json(new { code = "400", message = "帖子ID存在问题" })); } forum = await _forumSerivce.GetForumAsync(forum_id); int commentcount = _commentService.GetCommentCount(forum_id); //获取每页评价的数量 int pagecount = int.Parse(_configuration.GetSection("page_Setup:page_comment_count").Value); //设置评价所在页 int Locationpage; //如果帖子的评价数量小于规定的数量 if (commentcount < pagecount) { //设置所在页为1; Locationpage = 1; } else { //查看规定的数量(pagecount)能否除尽帖子数量(commentcount),如果除尽,证明下面将要添加的评论会在下一页显示 //所以所在页要在相除的数字基础上+1,如果除不尽,证明下面将要添加的评论还在相除的数字页面上 // Locationpage = commentcount % pagecount == 0 ? (commentcount / pagecount) + 1 : commentcount / pagecount; //下面是上面的简化 Locationpage = (commentcount / pagecount) + 1; } Comment comment = new Comment(); comment.forumID = forum_id; comment.Content = Content; comment.ID = Guid.NewGuid().ToString("N"); comment.UserID = user_id; comment.Create_Time = DateTime.Now; comment.LocationPage = Locationpage; try { await _commentService.AddCommentAsync(comment); //发布AddComment事件,使帖子的评价个数+1; _container.Publish("AddComment", new CommentSubmitEven() { category = 1, forumID = forum_id, publisherId = user_id, SubscriberId = forum.UserId, Comment_Id = comment.ID }); } catch (Exception ex) { _logger.LogError(ex.StackTrace); return(Json(new { code = "500", message = "发生错误" })); } return(Json(new { code = "200", message = "添加成功" })); }
public async Task <IActionResult> AddComment([FromBody] CommentModel comment) { await _commentService.AddCommentAsync(comment.UserID, comment.Content, comment.ProductID); return(Ok()); }