Пример #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);
        }
Пример #2
0
        /// <summary>
        /// 根据阅读量分组
        /// </summary>
        /// <returns></returns>
        public IList <ArticleDTO> GetGroupNewCount()
        {
            IList <Article>             articles        = _articleRepoistory.SelectGroupNewCount();
            IEnumerable <string>        accounts        = articles.Select(s => s.Author);
            Dictionary <string, string> accountWithName = _userRepoistory.AccountWithName(accounts);
            IList <ArticleDTO>          articleDTOs     = new List <ArticleDTO>();

            foreach (var item in articles)
            {
                ArticleDTO articleDTO = new ArticleDTO();
                articleDTO.Id             = item.Id;
                articleDTO.ArticleType    = Enum.GetName(typeof(ArticleType), item.ArticleType);
                articleDTO.Title          = item.Title;
                articleDTO.AuthorAccount  = item.Author;
                articleDTO.AuthorName     = accountWithName[item.Author];
                articleDTO.ContentBriefly = item.TextSection;
                articleDTO.CreateDate     = item.CreateTime.ToString("yyyy-MM-dd HH:mm");
                articleDTO.ReviewCount    = item.CommentCount;
                articleDTO.PraiseCount    = item.PraiseCount;
                articleDTO.ReadCount      = item.BrowserCount;
                articleDTOs.Add(articleDTO);
            }
            return(articleDTOs);
        }
Пример #3
0
        public async Task Create(string content, string account, string username, string authorization)
        {
            Whisper whisper = new Whisper();

            whisper.Account    = account;
            whisper.Content    = content;
            whisper.CreateTime = DateTime.Now;
            whisper            = _whisperRepoistory.Insert(whisper);

            WhisperDTO whisperDTO = new WhisperDTO();

            whisperDTO.Id          = whisper.Id.ToString();
            whisperDTO.Account     = whisper.Account;
            whisperDTO.AccountName = username;
            whisperDTO.Content     = content;
            whisperDTO.CreateDate  = whisper.CreateTime.ToString("yyyy-MM-dd HH:mm");

            long length = await _cacheClient.AddListTop(ConstantKey.CACHE_SQUARE_WHISPER, whisperDTO);

            int listLength = Convert.ToInt32(length);

            if (listLength > 12)
            {
                await _cacheClient.listPop(ConstantKey.CACHE_SQUARE_WHISPER);
            }
            List <WhisperDTO> whispers = await _cacheClient.ListRange <WhisperDTO>(ConstantKey.CACHE_SQUARE_WHISPER, 0, 6);

            List <WhisperDTO>           whisperDTOs     = new List <WhisperDTO>();
            Dictionary <string, string> accountWithName = _userRepository.AccountWithName(whispers.Select(s => s.Account));

            foreach (var item in whispers)
            {
                whisperDTO             = new WhisperDTO();
                whisperDTO.Id          = item.Id.ToString();
                whisperDTO.Account     = item.Account;
                whisperDTO.AccountName = accountWithName[item.Account];
                whisperDTO.Content     = item.Content;
                whisperDTO.CreateDate  = item.CreateDate;
                whisperDTOs.Add(whisperDTO);
            }

            HttpClient httpClient = _httpClientFactory.CreateClient();

            httpClient.DefaultRequestHeaders.Add("Authorization", authorization);
            string jsonValue = JsonConvert.SerializeObject(whisperDTOs);
            string httpUrl   = ConstantKey.GATEWAY_HOST + "/sms/singlar/whisper";

            try
            {
                var response = await httpClient.PostAsync(httpUrl, new StringContent(jsonValue, Encoding.UTF8, "application/json"));

                response.EnsureSuccessStatusCode();
                ApiResult apiResult = JsonConvert.DeserializeObject <ApiResult>(await response.Content.ReadAsStringAsync());
                if (apiResult.Code != HttpStatusCode.SUCCESS)
                {
                    throw new HttpRequestException(apiResult.Msg);
                }
            }
            catch (HttpRequestException ex)
            {
                LogUtils.LogError(ex, "WhisperService.Create", ex.Message);
            }
        }