public ApiResult CreateTidings([FromBody] TidingsDTO tidingsDTO) { _tidingsService.Create(tidingsDTO); return(ApiResult.Success()); }
/// <summary> /// 提交评论 /// </summary> public async Task PostComment(int articleId, CommentDTO commentDTO) { Article article = _articleRepoistory.SelectById(articleId); List <string> commentIds = article.CommentIdList; Comment comment = new Comment(); comment.Guid = Guid.NewGuid().ToString(); comment.Content = commentDTO.Content; comment.PostUser = commentDTO.PostUser; comment.RevicerUser = string.IsNullOrEmpty(commentDTO.Revicer) ? article.Author : commentDTO.Revicer; comment.CommentType = Enum.Parse <CommentType>(commentDTO.CommentType.ToString()); comment.PostDate = DateTime.Now; comment.AdditionalData = commentDTO.ToGuid; commentIds.Add(comment.Guid); TidingsDTO tidingsDTO = new TidingsDTO(); tidingsDTO.PostUserAccount = comment.PostUser; tidingsDTO.PostContent = comment.Content; tidingsDTO.ReviceUserAccount = comment.RevicerUser; tidingsDTO.Url = string.Format("../article/detail.html?id={0}", articleId); tidingsDTO.PostDate = DateTime.Now.ToString(); tidingsDTO.IsRead = false; tidingsDTO.CommentId = comment.Guid; if (comment.CommentType == CommentType.评论) { Comment toComment = _commentRepository.SelectById(commentDTO.ToGuid); tidingsDTO.Content = toComment.Content; } else { tidingsDTO.Content = article.Title; } using (TransactionScope trans = new TransactionScope()) { try { _commentRepository.Insert(comment); _articleRepoistory.UpdateCommentIds(commentIds, articleId); _tidingsService.Create(tidingsDTO); trans.Complete(); } catch (Exception ex) { LogUtils.LogError(ex, "ArticleService.PostComment", ex.Message); } } TidingsCondition tidingsCondition = new TidingsCondition(); tidingsCondition.Account = tidingsDTO.ReviceUserAccount; tidingsCondition.IsRead = false; int count = _tidingsService.SelectCount(tidingsCondition); HttpClient httpClient = _httpClientFactory.CreateClient(); Dictionary <string, string> requestContents = new Dictionary <string, string>(); requestContents.Add("user", tidingsDTO.ReviceUserAccount); requestContents.Add("count", count.ToString()); FormUrlEncodedContent formUrlEncodedContent = new FormUrlEncodedContent(requestContents); IHttpContextAccessor httpContext = ServiceLocator.Get <IHttpContextAccessor>(); httpContext.HttpContext.Request.Headers.TryGetValue("authorization", out StringValues authorization); httpClient.DefaultRequestHeaders.Add("Authorization", authorization.ToString()); HttpResponseMessage responseMessage = await httpClient.PostAsync(ConstantKey.GATEWAY_HOST + "/sms/singlar/tidings/count", formUrlEncodedContent); responseMessage.EnsureSuccessStatusCode(); ApiResult apiResult = JsonConvert.DeserializeObject <ApiResult>(await responseMessage.Content.ReadAsStringAsync()); if (apiResult.Code != HttpStatusCode.SUCCESS) { throw new HttpRequestException(apiResult.Msg); } }