public void Delete_By_Topic_With_Multiple_Topics_Per_Tag() { var tagRepository = Substitute.For <ITopicTagRepository>(); var topicRepository = Substitute.For <ITopicRepository>(); var topicTagService = new TopicTagService(tagRepository, topicRepository); var topicTag = new TopicTag { Tag = "tag-one", Topics = new List <Topic> { new Topic { Name = "Tony" }, new Topic { Name = "Stark" } } }; var topic = new Topic { Tags = new List <TopicTag> { topicTag } }; topicTagService.DeleteByTopic(topic); Assert.IsFalse(topicTag.Topics.Count() <= 1); tagRepository.DidNotReceive().Delete(Arg.Is(topicTag)); }
public virtual IList <TopicTag> GetAllTopicsTags(int storeId, bool showHidden = false) { var topicTags = new List <TopicTag>(); var topics = GetAllTopics(storeId: storeId, showHidden: showHidden); foreach (var topic in topics) { var tags = this.ParseTags(topic); foreach (var tag in tags) { var foundTopicTag = topicTags.Find(bpt => bpt.Name.Equals(tag, StringComparison.InvariantCultureIgnoreCase)); if (foundTopicTag == null) { foundTopicTag = new TopicTag { Name = tag, TopicCount = 1 }; topicTags.Add(foundTopicTag); } else { foundTopicTag.TopicCount++; } } } return(topicTags); }
public void Delete_By_Topic_With_One_Topics_Per_Tag() { var tagRepository = Substitute.For <ITopicTagRepository>(); var topicRepository = Substitute.For <ITopicRepository>(); var topicTagService = new TopicTagService(tagRepository, topicRepository); var topicTag = new TopicTag { Tag = "tag-one", Topics = new List <Topic> { new Topic { Name = "HulkRules" } } }; var topic = new Topic { Tags = new List <TopicTag> { topicTag } }; topicTagService.DeleteByTopic(topic); Assert.IsTrue(topicTag.Topics.Count() <= 1); tagRepository.Received().Delete(Arg.Is(topicTag)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,TagValue")] TopicTag topicTag) { if (id != topicTag.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(topicTag); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TopicTagExists(topicTag.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(topicTag)); }
public IList<TagNotification> GetByTag(TopicTag tag) { return _context.TagNotification .Include(x => x.User) .Where(x => x.Tag.Id == tag.Id) .AsNoTracking() .ToList(); }
public IList <TagNotification> GetByTag(TopicTag tag) { return(_context.TagNotification .Include(x => x.User) .Where(x => x.Tag.Id == tag.Id) .AsNoTracking() .ToList()); }
/// <summary> /// 构造函数 /// </summary> /// <param name="messageType">消息类别,分为BASE,ORDER,TRAN</param> /// <param name="topicTag">主题标签,用{Topic}.{Tag}格式的枚举实现</param> public AbstractProducerService(ONSMessageType messageType, Enum topicTag) { this.MessageType = messageType; this.TopicTag = topicTag; this.Topic = (_Environment + "_" + TopicTag.GetType().Name).ToUpper(); this.Tag = TopicTag.ToString(); this.Pid = ("PID_" + this.Topic).ToUpper(); }
public void Update(TopicTag item) { // Check there's not an object with same identifier already in context if (_context.TopicTag.Local.Select(x => x.Id == item.Id).Any()) { throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit"); } _context.Entry(item).State = EntityState.Modified; }
public IList<TagNotification> GetByUserAndTag(MembershipUser user, TopicTag tag, bool addTracking = false) { var notifications = _context.TagNotification .Where(x => x.User.Id == user.Id && x.Tag.Id == tag.Id); if (addTracking) { return notifications.ToList(); } return notifications.AsNoTracking().ToList(); }
public async Task <IActionResult> Create([Bind("Id,TagValue")] TopicTag topicTag) { if (ModelState.IsValid) { _context.Add(topicTag); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(topicTag)); }
public IList <TagNotification> GetByUserAndTag(MembershipUser user, TopicTag tag, bool addTracking = false) { var notifications = _context.TagNotification .Where(x => x.User.Id == user.Id && x.Tag.Id == tag.Id); if (addTracking) { return(notifications.ToList()); } return(notifications.AsNoTracking().ToList()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } TopicTag = await _context.TopicTags.FirstOrDefaultAsync(m => m.Id == id); if (TopicTag == null) { return(NotFound()); } return(Page()); }
public void Add_Test_With_Null_Tags() { var tagRepository = Substitute.For <ITopicTagRepository>(); var topicRepository = Substitute.For <ITopicRepository>(); var topicTagService = new TopicTagService(tagRepository, topicRepository); var topic = new Topic { Tags = new List <TopicTag>() }; var topicTag = new TopicTag(); topicTagService.Add(string.Empty, topic); Assert.IsTrue(!topic.Tags.Any()); tagRepository.DidNotReceive().Update(Arg.Is(topicTag)); }
/// <summary> /// Add new tags to a topic, ignore existing ones /// </summary> /// <param name="tags"></param> /// <param name="topic"></param> public void Add(string tags, Topic topic) { if (!string.IsNullOrWhiteSpace(tags)) { tags = StringUtils.SafePlainText(tags); var newTagNames = tags.ToLower().TrimStart().TrimEnd() .Replace(" ", "-").Split(',') .Select(tag => tag) .Where(x => !string.IsNullOrWhiteSpace(x)) .Distinct(); if (topic.Tags == null) { topic.Tags = new List <TopicTag>(); } var entityTags = new List <TopicTag>(); foreach (var newTag in newTagNames) { var tag = GetTagName(newTag); if (tag != null) { // Exists entityTags.Add(tag); } else { // Doesn't exists var nTag = new TopicTag { Tag = newTag, Slug = ServiceHelpers.CreateUrl(newTag) }; Add(nTag); entityTags.Add(nTag); } } topic.Tags = entityTags; // Fire the tag badge check _badgeService.ProcessBadge(BadgeType.Tag, topic.User); } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } TopicTag = await _context.TopicTags.FindAsync(id); if (TopicTag != null) { _context.TopicTags.Remove(TopicTag); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
/// <summary> /// Add new tags to a topic, ignore existing ones /// </summary> /// <param name="tags"></param> /// <param name="topic"></param> 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 = _tagRepository.GetTagName(newTag); if (tag != null) { // Exists existingTags.Add(tag); } else { // Doesn't exists var nTag = new TopicTag { Tag = newTag, Slug = ServiceHelpers.CreateUrl(newTag) }; _tagRepository.Add(nTag); newTags.Add(nTag); } } newTags.AddRange(existingTags); topic.Tags = newTags; // Fire the tag badge check _badgeService.ProcessBadge(BadgeType.Tag, topic.User); } }
private void BindItem() { string type = listtype; if (type == null) { return; } if (type == "topic") { //this.topiccount = Topics.GetTopicCountByTagId(this.tagid); this.topiccount = TopicTag.FindTidCountByTagID(tagid); this.SetPage(this.topiccount); if (this.topiccount > 0) { this.topiclist = Topics.GetTopicListByTagId(this.tagid, this.pageid, this.config.Tpp); this.pagenumbers = Utils.GetPageNumbers(this.pageid, this.pagecount, "tags.aspx?t=topic&tagid=" + this.tagid, 8); return; } base.AddErrLine("该标签下暂无主题"); } }
/// <summary> /// Create a new topic tag /// </summary> /// <param name="topicTag"></param> /// <returns></returns> public TopicTag Add(TopicTag topicTag) { _context.TopicTag.Add(topicTag); return(topicTag); }
/// <summary> /// Create a new topic tag /// </summary> /// <param name="topicTag"></param> /// <returns></returns> public TopicTag Add(TopicTag topicTag) { return _tagRepository.Add(topicTag); }
/// <summary> /// Add new tags to a topic if they are allowed, ignore existing ones, remove ones that have been deleted /// </summary> /// <param name="tags"></param> /// <param name="topic"></param> /// <param name="isAllowedToAddTags"></param> public void Add(string[] tags, Topic topic, bool isAllowedToAddTags) { if (topic.Tags == null) { topic.Tags = new List <TopicTag>(); } foreach (var newTag in tags) { var tagExists = false; // Check it's not already in the list foreach (var topicTag in topic.Tags) { if (topicTag.Tag == newTag) { tagExists = true; break; } } // Continue if tag doesn't already exist on topic if (!tagExists) { var tag = GetTagName(newTag); if (tag != null) { // Exists topic.Tags.Add(tag); } else if (isAllowedToAddTags) { // Doesn't exists var nTag = new TopicTag { Tag = newTag, Slug = ServiceHelpers.CreateUrl(newTag) }; //Add(nTag); topic.Tags.Add(nTag); } } } // Find tags that don't exist now var tagsRemoved = new List <TopicTag>(); foreach (var topicTag in topic.Tags) { var hasTag = false; // Finally check for removed tags foreach (var tag in tags) { if (topicTag.Tag == tag) { hasTag = true; } } if (hasTag == false) { tagsRemoved.Add(topicTag); } } // Now remove from Topic foreach (var topicTag in tagsRemoved) { topic.Tags.Remove(topicTag); } }
private void UpdateInfo(TopicTag topicTag, DalTopicTag dalTopicTag) { if (topicTag == null || dalTopicTag == null) throw new ArgumentNullException(); topicTag.Id = dalTopicTag.Id; topicTag.Tag = dalTopicTag.Tag; }
/// <summary> /// Add new tags to a topic, ignore existing ones /// </summary> /// <param name="tags"></param> /// <param name="topic"></param> 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 = GetTagName(newTag); if (tag != null) { // Exists existingTags.Add(tag); } else { // Doesn't exists var nTag = new TopicTag { Tag = newTag, Slug = ServiceHelpers.CreateUrl(newTag) }; Add(nTag); newTags.Add(nTag); } } newTags.AddRange(existingTags); topic.Tags = newTags; // Fire the tag badge check _badgeService.ProcessBadge(BadgeType.Tag, topic.User); } }
public void Delete(TopicTag item) { _context.TopicTag.Remove(item); }
private TopicTag ToOrmTopicTag(DalTopicTag dalTopicTag) { if (dalTopicTag == null) return null; var newTopicTag = new TopicTag(); UpdateInfo(newTopicTag, dalTopicTag); return newTopicTag; }
public IList <TagNotification> GetByUserAndTag(MembershipUser user, TopicTag tag, bool addTracking = false) { return(_notificationRepository.GetByUserAndTag(user, tag, addTracking)); }
public IList <TagNotification> GetByTag(TopicTag tag) { return(_notificationRepository.GetByTag(tag)); }
public void Delete(TopicTag item) { _context.TopicTag.Remove(item); }
/// <summary> /// Create a new topic tag /// </summary> /// <param name="topicTag"></param> /// <returns></returns> public TopicTag Add(TopicTag topicTag) { _context.TopicTag.Add(topicTag); return topicTag; }