Esempio n. 1
0
        public void Insert(InsertArticleInput model)
        {
            if (string.IsNullOrWhiteSpace(model.Title))
            {
                throw new JIFException("文章标题不能为空");
            }

            if (string.IsNullOrWhiteSpace(model.Content) && string.IsNullOrWhiteSpace(model.MarkdownContent))
            {
                throw new JIFException("文章内容不能为空");
            }

            var article = new Article
            {
                Title           = model.Title,
                MarkdownContent = model.MarkdownContent,
                Content         = model.Content,
                PublishTime     = model.PublishTime,
                CategoryId      = model.CategoryId,
                AllowComments   = model.AllowComments,
                IsPublished     = model.IsPublished,
                CreateTime      = DateTime.Now,
                CreateUserId    = _workContext.CurrentUser.Id
            };

            _articleRepository.Insert(article);

            // 保存文章标签
            SaveArticleTags(article.Id, model.Tags);
        }
Esempio n. 2
0
        public JsonResult Save(int id, InsertArticleInput model)
        {
            if (id == 0)
            {
                _articleService.Insert(model);
            }
            else
            {
                _articleService.Update(id, model);
            }


            return(JsonOk());
        }
Esempio n. 3
0
        public void Update(int id, InsertArticleInput model)
        {
            if (string.IsNullOrWhiteSpace(model.Title))
            {
                throw new JIFException("文章标题不能为空");
            }


            if (string.IsNullOrWhiteSpace(model.Content) && string.IsNullOrWhiteSpace(model.MarkdownContent))
            {
                throw new JIFException("文章内容不能为空");
            }

            var entity = GetArticle(id);

            if (entity == null)
            {
                throw new JIFException("欲修改文章不存在");
            }

            entity.Title           = model.Title;
            entity.MarkdownContent = model.MarkdownContent;
            entity.Content         = model.Content;
            entity.PublishTime     = model.PublishTime;
            entity.CategoryId      = model.CategoryId;
            entity.AllowComments   = model.AllowComments;
            entity.IsPublished     = model.IsPublished;
            entity.UpdateTime      = DateTime.Now;
            entity.UpdateUserId    = _workContext.CurrentUser.Id;

            _articleRepository.Update(entity);

            // 保存文章标签, 先删除原有文章标签
            _articleTagRepository.Delete(_articleTagRepository.Table.Where(d => d.ArticleId == id));
            SaveArticleTags(id, model.Tags);
        }
Esempio n. 4
0
 public IHttpActionResult UpdateArticle(int id, InsertArticleInput model)
 {
     _articleService.Update(id, model);
     return(JsonOk("文章修改成功"));
 }
Esempio n. 5
0
 public IHttpActionResult AddArticle(InsertArticleInput model)
 {
     _articleService.Insert(model);
     return(JsonOk("文章添加成功"));
 }