Example #1
0
        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;
            }
        }
Example #2
0
 public TopicTag Add(TopicTag topicTag)
 {
     return _tagRepository.Add(topicTag);
 }
Example #3
0
 public TopicTag Add(TopicTag topicTag)
 {
     _context.TopicTag.Add(topicTag);
     return topicTag;
 }
Example #4
0
 public void Delete(TopicTag item)
 {
     _context.TopicTag.Remove(item);
 }
Example #5
0
 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;
 }