Example #1
0
        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);
        }
Example #2
0
        public IList <TidingsModel> SelectByPage(int pageIndex, int pageSize, TidingsCondition TidingsCondition = null)
        {
            IList <Tidings> tidingsList = _tidingsRepository.SelectByPage(pageIndex, pageSize, TidingsCondition);
            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.SelectNameWithAccountDic(accounts.Distinct());
            IList <TidingsModel>        tidingsModels = new List <TidingsModel>();

            foreach (var item in tidingsList)
            {
                TidingsModel tidingsModel = new TidingsModel();
                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.SendDate.ToString("yyyy-MM-dd hh:mm");
                tidingsModels.Add(tidingsModel);
            }
            return(tidingsModels);
        }
Example #3
0
        public ApiResult Tidings([FromBody] TidingsCondition condition)
        {
            UserDTO userDTO = GetLoginUser();

            condition.IsRead  = false;
            condition.Account = userDTO.Account;
            List <TidingsDTO> tidingsDTOs = _tidingsService.GetTidingsDTOs(condition.CurrentPage, condition.PageSize, condition);

            return(ApiResult.Success(tidingsDTOs));
        }
Example #4
0
        public ApiResult GetTidings(int pageIndex, int pageSize)
        {
            UserModel        userModel        = Auth.GetLoginUser(_httpContext);
            TidingsCondition tidingsCondition = new TidingsCondition();

            tidingsCondition.Account = userModel.Account;
            tidingsCondition.IsRead  = false;
            IList <TidingsModel> tidingsModels = _tidingsService.SelectByPage(pageIndex, pageSize, tidingsCondition);

            return(ApiResult.Success(tidingsModels));
        }
Example #5
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));
        }
Example #6
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 }));
        }
Example #7
0
        public IList <Tidings> SelectByPage(int pageIndex, int pageSize, TidingsCondition TidingsCondition = null)
        {
            int pageId = pageSize * (pageIndex - 1);
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("pageId", pageId);
            parameters.Add("pageSize", pageSize);
            string where = Where(TidingsCondition, ref parameters);
            string sql = "SELECT tidings_id,tidings_postuser,tidings_postcontent,tidings_reviceuser,tidings_senddate,tidings_isread,tidings_additionaldata,tidings_url "
                         + " FROM T_Tidings  WHERE " + where + " ORDER BY tidings_id DESC LIMIT @pageId,@pageSize";
            IEnumerable <dynamic> dynamics = Select(sql, parameters);

            return(Map(dynamics));
        }
Example #8
0
        private string Where(TidingsCondition condition, ref DynamicParameters parameters)
        {
            IList <string> sqlList = new List <string>();

            if (!string.IsNullOrEmpty(condition.Account))
            {
                parameters.Add("account", condition.Account);
                sqlList.Add("tidings_reviceuser = @account");
            }
            if (condition.IsRead.HasValue)
            {
                parameters.Add("isread", condition.IsRead.Value);
                sqlList.Add("tidings_isread = @isread");
            }
            sqlList.Add(" 1=1 ");
            string sql = string.Join(" AND ", sqlList);

            return(sql);
        }
Example #9
0
 public int SelectCount(TidingsCondition tidingsCondition = null)
 {
     Expression <Func <Tidings, bool> > where = TidingsCondition.BuildExpression(tidingsCondition);
     return(_tidingsRepository.SelectCount(where));
 }
Example #10
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);
            }
        }