예제 #1
0
        public ResultDto AddEssay(EssayEntity essayEntity, IEnumerable <MediaEntity> mediaList)
        {
            /*private static readonly Regex _regex = new Regex(@"(?'group1'#)([^#]+?)(?'-group1'#)");
             * if ((!this.EssayContent.IsNullOrEmpty()) && _regex.IsMatch(this.EssayContent))
             *  {
             *      var matchCollection = _regex.Matches(this.EssayContent);
             *      return matchCollection.First()?.Value.Replace("#","");
             *  }*/

            var createUserId = _kardSession.UserId.Value;
            IEnumerable <TagEntity> tagList = new List <TagEntity>();

            if (essayEntity.Content.Contains('#'))
            {
                var contentList          = essayEntity.Content.Split('#');
                int contentListLastIndex = contentList.Length - 1;
                tagList = contentList.Where((item, index) => ((!string.IsNullOrEmpty(item)) && (index != contentListLastIndex))).Select((item, index) => { var tagEntity = new TagEntity {
                                                                                                                                                               Sort = (index + 1), TagName = item
                                                                                                                                                           }; tagEntity.AuditCreation(createUserId); return(tagEntity); });
                essayEntity.Content = contentList.Last();
            }
            essayEntity.Location = "广州";
            essayEntity.AuditCreation(createUserId);
            mediaList.AuditCreation(createUserId);
            var result = _defaultRepository.AddEssay(essayEntity, tagList, mediaList);

            if (result)
            {
                string cacheKey = $"homeCover[{DateTime.Now.ToString("yyyyMMdd")}]";
                _memoryCache.Remove(cacheKey);
            }
            return(new ResultDto {
                Result = result
            });
        }
예제 #2
0
        public async Task <ResultDto <long> > Add(EssayEntity essayEntity, EssayContentEntity essayContentEntity, IEnumerable <TagEntity> tagList)
        {
            var userId = _kardSession.UserId.Value;

            essayEntity.SubContent = Utils.ContentRegex.Replace(essayContentEntity.Content, "");
            if (essayEntity.SubContent.Length > 100)
            {
                essayEntity.SubContent = essayEntity.SubContent.Remove(100) + "...";
            }

            essayEntity.IsPublish      = essayEntity.IsPublish;
            essayEntity.Location       = Utils.GetCity(HttpContext, _memoryCache);
            essayEntity.Score          = essayEntity.Score > 0 ? essayEntity.Score : 6m;
            essayEntity.ScoreHeadCount = 1;
            essayEntity.AuditCreation(userId);
            tagList.AuditCreation(userId);
            var resultDto = _repositoryFactory.GetRepository <IEssayRepository>().AddEssay(essayEntity, essayContentEntity, tagList);

            if (resultDto.Result)
            {
                var createHtmlResult = await CreateHtml(resultDto.Data);

                essayEntity.PageUrl = createHtmlResult.Data;
                await _defaultRepository.UpdateAsync(essayEntity);

                _baiduspiderAppService.Baiduspider(essayEntity.PageUrl);
                //string cacheKey = $"homeCover[{DateTime.Now.ToString("yyyyMMdd")}]";
                //_memoryCache.Remove(cacheKey);
            }


            return(await Task.FromResult(resultDto));
        }