public List <TidingsDTO> GetTidingsDTOs(int currentPage, int pageSize, TidingsCondition tidingsCondition = null) { Expression <Func <Tidings, bool> > where = TidingsCondition.BuildExpression(tidingsCondition); List <Tidings> tidingsList = _tidingsRepository.SelectByPage(currentPage, pageSize, where).ToList(); List <string> accounts = new List <string>(); accounts.AddRange(tidingsList.Select(s => s.PostUser)); accounts.AddRange(tidingsList.Select(s => s.ReviceUser)); Dictionary <string, string> dic = _userRepository.AccountWithName(accounts.Distinct()); List <TidingsDTO> tidingsModels = new List <TidingsDTO>(); foreach (var item in tidingsList) { TidingsDTO tidingsModel = new TidingsDTO(); tidingsModel.Id = item.Id; tidingsModel.Content = item.AdditionalData; tidingsModel.IsRead = item.IsRead; tidingsModel.PostContent = item.PostContent; tidingsModel.PostUserAccount = item.PostUser; tidingsModel.PostUsername = dic[item.PostUser]; tidingsModel.ReviceUsername = dic[item.ReviceUser]; tidingsModel.ReviceUserAccount = item.ReviceUser; tidingsModel.Url = item.Url; tidingsModel.PostDate = item.CreateTime.ToString("yyyy-MM-dd hh:mm"); tidingsModels.Add(tidingsModel); } return(tidingsModels); }
public void Create(TidingsDTO tidingsDTO) { Tidings tidings = new Tidings(); tidings.PostContent = tidingsDTO.PostContent; tidings.PostUser = tidingsDTO.PostUserAccount; tidings.ReviceUser = tidingsDTO.ReviceUserAccount; tidings.Url = tidingsDTO.Url; tidings.CreateTime = Convert.ToDateTime(tidingsDTO.PostDate); tidings.CommentId = tidingsDTO.CommentId; tidings.IsRead = tidingsDTO.IsRead; tidings.AdditionalData = tidingsDTO.Content; _tidingsRepository.Insert(tidings); }
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); } }