Пример #1
0
        public ApiResult GetUser()
        {
            UserDTO          userDTO          = Auth.GetLoginUser();
            TidingsCondition tidingsCondition = new TidingsCondition();

            tidingsCondition.Account = userDTO.Account;
            tidingsCondition.IsRead  = false;
            int count = _tidingsService.SelectCount(tidingsCondition);

            return(ApiResult.Success(new { photo = userDTO.HeadPhoto, count = count, account = userDTO.Account }));
        }
Пример #2
0
        public ApiResult TidingsCount()
        {
            UserDTO          userDTO   = GetLoginUser();
            TidingsCondition condition = new TidingsCondition();

            condition.IsRead  = false;
            condition.Account = userDTO.Account;
            int count = _tidingsService.SelectCount(condition);

            return(ApiResult.Success(count));
        }
Пример #3
0
        /// <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);
            }
        }