public Post AddNewPost(string postContent, Topic topic, User user, out PermissionSet permissions) { permissions = _roleService.GetPermissions(topic.Category, UsersRole(user)); if (permissions[AppConstants.PermissionDenyAccess].IsTicked || permissions[AppConstants.PermissionReadOnly].IsTicked) { throw new ApplicationException(""); } var comment = new Post { PostContent = postContent, User = user, Topic = topic, IpAddress = StringUtils.GetUsersIpAddress(), PostType = PostType.comment.ToString(), DateCreated = DateTime.UtcNow, DateEdited = DateTime.UtcNow }; comment = SanitizePost(comment); Add(comment); return comment; }
public Topic Add(Topic topic) { topic = SanitizeTopic(topic); topic.CreateDate = DateTime.UtcNow; //此处应有修改 topic.Slug = topic.Name; return this._topicRepository.Add(topic); }
public void DeleteByTopic(Topic topic) { var tags = topic.Tags; foreach (var topicTag in tags) { // If this tag has a count of topics greater than this one topic // then its tagged by more topics so don't delete if (topicTag.Topics.Count() <= 1) { _tagRepository.Delete(topicTag); } } }
public Topic AddLastPost(Topic topic, string postContent) { topic = SanitizeTopic(topic); var post = new Post { DateCreated = DateTime.UtcNow, DateEdited = DateTime.UtcNow, PostContent = StringUtils.GetSafeHtml(postContent), User = topic.User, Topic = topic, IpAddress = StringUtils.GetUsersIpAddress(), PostType = "topic" }; this._postRepository.Add(post); topic.Posts.Add(post); return topic; }
public void Add(string tags, Topic topic) { if (!string.IsNullOrEmpty(tags)) { tags = StringUtils.SafePlainText(tags); var splitTags = tags.Replace(" ", "").Split(','); if (topic.Tags == null) { topic.Tags = new List<TopicTag>(); } var newTagNames = splitTags.Select(tag => tag); var newTags = new List<TopicTag>(); var existingTags = new List<TopicTag>(); foreach (var newTag in newTagNames.Distinct()) { var tag = this._tagRepository.GetTagName(newTag); if (tag != null) { existingTags.Add(tag); tag.Topics.Add(topic); } else { var nTag = new TopicTag { Tag = newTag, Slug = ServiceHelpers.CreateUrl(newTag), Topics = new List<Topic> { topic } }; this._tagRepository.Add(nTag); newTags.Add(nTag); } } newTags.AddRange(existingTags); topic.Tags = newTags; } }
public Topic Add(Topic topic) { this._context.Topic.Add(topic); return topic; }
public ActionResult New(CreateTopicViewModel model) { if(ModelState.IsValid) { Category category; var topic = new Topic(); using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { category = this._categoryService.Get(model.Category); var permissions = RoleService.GetPermissions(category, UsersRole); if (permissions[AppConstants.PermissionDenyAccess].IsTicked || permissions[AppConstants.PermissionReadOnly].IsTicked || permissions[AppConstants.PermissionCreateTopics].IsTicked) { ModelState.AddModelError(string.Empty, "No Permission"); } else { topic = new Topic { Name = model.Name, Category = category, User = LoggedOnUser }; if (!string.IsNullOrEmpty(model.Content)) { topic = this._topicService.Add(topic); unitOfWork.SaveChanges(); this._topicService.AddLastPost(topic, model.Content); // 添加标签 if (!string.IsNullOrEmpty(model.Tags)) { this._topicTagService.Add(model.Tags.ToLower(), topic); } try { unitOfWork.Commit(); return Redirect(topic.NiceUrl); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); ModelState.AddModelError(string.Empty, "添加主题失败"); } } else { unitOfWork.Rollback(); ModelState.AddModelError(string.Empty, "添加主题失败"); } } } } return RedirectToAction("New"); }
public IEnumerable<TopicTag> GetByTopic(Topic topic) { return this._tagRepository.GetByTopic(topic); }
public Topic SanitizeTopic(Topic topic) { topic.Name = StringUtils.SafePlainText(topic.Name); return topic; }
public IEnumerable<TopicTag> GetByTopic(Topic topic) { return _context.TopicTag .Where(x => x.Topics.Contains(topic)) .ToList(); }