public void Handle(CreateArticleTagCommand command) { var user = _userRepository.Load(command.UserId); Guard.IsNotNull(user, "user"); var query = (from a in _articleTagRepository.FindAll() let u = a.User where u.Id == command.UserId && a.TagName == command.TagName select a); if (query.Count() > 0) { throw new BusinessException("已经存在相同的文章标签名称!"); } _articleTagRepository.Save(new ArticleTag() { TagName = command.TagName, IsShow = command.IsShow, User = user, CreateDate = DateTime.Now, LastDateTime = DateTime.Now }); }
public void Handle(UpdateArticleTagCommand command) { var articleTag = _articleTagRepository.Load(command.ArticleTagId); Guard.IsNotNull(articleTag, "articleTag"); if (articleTag.User.Id != command.CurrentUserId) { throw new BusinessException("非法操作"); return; } var isHaveArticleTag = (from query in _articleTagRepository.FindAll() where query.TagName == command.TagName && query.Id != articleTag.Id select query); if (isHaveArticleTag.Count() > 0) { throw new BusinessException("已经存在相同的文章标签名称!"); } if (command.IsShow != null) { articleTag.IsShow = (bool)command.IsShow; } if (!string.IsNullOrEmpty(command.TagName)) { articleTag.TagName = command.TagName.Trim(); } articleTag.LastDateTime = DateTime.Now; _articleTagRepository.SaveOrUpdate(articleTag); }
public int Handle(CreateArticleCommand command) { var user = _userRepository.Load(command.UserId); Guard.IsNotNull(user, "没有该用户"); var articleTags = new List <ArticleTag>(); if (command.ArticleTagIds != null) { articleTags = (from a in _articleTagRepository.FindAll() where command.ArticleTagIds.Contains(a.Id) select a).ToList(); } var article = new Article() { Content = HttpUtility.HtmlEncode(command.Content), IsShow = command.IsShow, ReadCount = 0, Title = HttpUtility.HtmlEncode(command.Title), UrlQuoteUrl = command.UrlQuoteUrl, User = user, LastDateTime = DateTime.Now, CreateDate = DateTime.Now }; if (string.IsNullOrEmpty(command.ContentDesc)) { if (command.Content != null) { article.ContentDesc = " " + Utils.CutStringBySuffix(Utils.RemoveHtml(command.Content), 0, 300, "..."); } } else { article.ContentDesc = HttpUtility.HtmlEncode(command.ContentDesc); } if (command.ArticleTypeId != null && command.ArticleTypeId > 0) { var articleType = _articleTypeRepository.Load(Convert.ToInt32(command.ArticleTypeId)); Guard.IsNotNull(articleType, "没有该文章类型"); article.ArticleType = articleType; } article.SetArticleTage(articleTags); var result = _articleRepository.Save(article); return(result.Id); }
public void Handle(UpdateArticleCommand command) { var article = _articleRepository.Get(command.ArticleId); Guard.IsNotNull(article, "没有该文章"); if (command.IsCheckUserState && article.User.Id != command.UserId) { throw new PowerException("非法操作"); } if (!string.IsNullOrEmpty(command.Title)) { article.Title = HttpUtility.HtmlEncode(command.Title); } if (!string.IsNullOrEmpty(command.Content)) { article.Content = HttpUtility.HtmlEncode(command.Content); } if (command.ReadCount > 0) { article.ReadCount = command.ReadCount; } if (command.ArticleTagIds != null && command.ArticleTagIds.Count() > 0) { var articleTags = (from a in _articleTagRepository.FindAll() where command.ArticleTagIds.Contains(a.Id) select a).ToList(); Guard.IsNotNull(articleTags, "找不到该文章标签"); article.SetArticleTage(articleTags); } if (command.ArticleTypeId != null && command.ArticleTypeId > 0) { var articleType = _articleTypeRepository.Load(Convert.ToInt32(command.ArticleTypeId)); Guard.IsNotNull(articleType, "找不到该文章类型"); article.ArticleType = articleType; } else { article.ArticleType = null; } if (string.IsNullOrEmpty(command.ContentDesc)) { if (!string.IsNullOrEmpty(command.Content)) { article.ContentDesc = " " + Utils.CutStringBySuffix(Utils.RemoveHtml(command.Content), 0, 300, "..."); } } else { article.ContentDesc = HttpUtility.HtmlEncode(command.ContentDesc); } if (!string.IsNullOrEmpty(command.UrlQuoteUrl)) { article.UrlQuoteUrl = command.UrlQuoteUrl; } if (command.IsShow != null) { article.IsShow = (bool)command.IsShow; } article.LastDateTime = DateTime.Now; _articleRepository.SaveOrUpdate(article); }