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> 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();
 }
Esempio n. 3
0
        /// <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;
            }
        }
        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));
        }
        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 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));
        }
Esempio n. 7
0
 /// <summary>
 /// Create a new topic tag
 /// </summary>
 /// <param name="topicTag"></param>
 /// <returns></returns>
 public TopicTag Add(TopicTag topicTag)
 {
     return _tagRepository.Add(topicTag);
 }
 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);
 }
 public TopicTag Add(TopicTag topicTag)
 {
     _context.TopicTag.Add(topicTag);
     return topicTag;
 }
 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;  
 }