Example #1
0
        public async Task <EntityNews> AddNewsAsync(EntityNews entityNews)
        {
            var newsRep = GetRepositoryInstance <TableNews>();

            //var newsRep = GetRepositoryInstance<TableNews>();

            //新闻已存在,直接返回
            if (newsRep.Find(x => x.Title == entityNews.Title) != null)
            {
                return(entityNews);
            }

            var model = new TableNews
            {
                NewsId       = GuidExtens.GuidTo16String(),
                Title        = entityNews.Title,
                ShortContent = entityNews.ShortContent,
                NewsContent  = entityNews.Content,
                CreateTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                UpdateTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                IsEnable     = true,
                HrefUrl      = entityNews.HrefUrl ?? "",
                Media        = entityNews.Media ?? "",
                NewsImgUrl   = "",
                NewsType     = entityNews.NewsType
            };
            await newsRep.InsertAsync(model);

            entityNews.NewsId = model.NewsId;
            return(entityNews);
        }
Example #2
0
        public async Task <ResponseModel> AddNewsAsync([FromBody] EntityNews entityNews)
        {
            var newsInfo = await NewsService.AddNewsAsync(entityNews);

            await UpdateNewsImgAsync(newsInfo);

            return(Success(newsInfo));
        }
Example #3
0
        public async Task <ResponseModel> UpdateNewsAsync([FromBody] EntityNews entityNews)
        {
            if (string.IsNullOrEmpty(entityNews.NewsId))
            {
                return(Fail(ErrorCodeEnum.ParamIsNullArgument));
            }
            await NewsService.UpateNewsAsync(entityNews);

            await UpdateNewsImgAsync(entityNews);

            await _mediator.Send(new NewsChangeCommands(entityNews));

            return(Success("更新成功"));
        }
Example #4
0
        public async Task UpateNewsAsync(EntityNews entityNews)
        {
            var newsRep = GetRepositoryInstance <TableNews>();
            var model   = await newsRep.FindAsync(x => x.NewsId == entityNews.NewsId);

            if (model == null)
            {
                return;
            }

            model.Title        = entityNews.Title ?? model.Title;
            model.ShortContent = entityNews.ShortContent ?? model.ShortContent;
            model.NewsContent  = entityNews.Content ?? model.NewsContent;
            model.HrefUrl      = entityNews.HrefUrl ?? model.HrefUrl;
            model.Media        = entityNews.Media ?? model.Media;
            model.IsEnable     = entityNews.IsEnable;
            model.UpdateTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            newsRep.Update(model);
        }
 public NewsChangeCommands(EntityNews newsInfo)
 {
     NewsInfo = newsInfo;
 }
Example #6
0
 private async Task UpdateNewsImgAsync(EntityNews entityNews)
 {
     var imgUrl = UploadQiNiu(NewsService.GetNewsShareImgAsync(entityNews.Title, entityNews.ShortContent));
     await NewsService.UpateNewsImgAsync(entityNews.NewsId, imgUrl);
 }