public static void DeleteTopicTags(int topicid) { //UPDATE [dnt_tags] SET [count]=[count]-1,[fcount]=[fcount]-1 //WHERE EXISTS (SELECT [tagid] FROM [dnt_topictags] WHERE [tid] = @tid AND [tagid] = [dnt_tags].[tagid]) //DELETE FROM [dnt_topictags] WHERE [tid] = @tid var list = TopicTag.FindAllByTid(topicid); if (list.Count <= 0) { return; } using (var trans = Meta.CreateTrans()) { foreach (var tp in list) { tp.Delete(); var tag = FindByID(tp.TagID); if (tag == null) { continue; } tag.Count--; tag.FCount--; tag.Update(); } } }
public static EntityList <Tag> GetTagsListByTopic(int topicid) { var list = TopicTag.FindAllByTid(topicid); if (list.Count <= 0) { return(new EntityList <Tag>()); } //return FindAll(_.ID.In(list.GetItem<Int32>(TopicTag._.TagID)), null, null, 0, 0); return(FindAllByIDs(list.GetItem <Int32>(TopicTag._.TagID).ToArray())); }
public static void CreateTopicTags(string[] tagArray, int topicId, int userId, string currentDateTime) { //EXEC [dnt_createtags] @tags, @userid, @postdatetime //INSERT INTO [dnt_tags]([tagname], [userid], [postdatetime], [orderid], [color], [count], [fcount], [pcount], [scount], [vcount]) // SELECT [item], @userid, @postdatetime, 0, '', 0, 0, 0, 0, 0 FROM [dnt_split](@tags, ' ') AS [newtags] // WHERE NOT EXISTS (SELECT [tagname] FROM [dnt_tags] WHERE [newtags].[item] = [tagname]) //UPDATE [dnt_tags] SET [fcount]=[fcount]+1,[count]=[count]+1 //WHERE EXISTS (SELECT [item] FROM [dnt_split](@tags, ' ') AS [newtags] WHERE [newtags].[item] = [tagname]) //INSERT INTO [dnt_topictags] (tagid, tid) //SELECT tagid, @tid FROM [dnt_tags] WHERE EXISTS (SELECT [item] FROM [dnt_split](@tags, ' ') WHERE [item] = [dnt_tags].[tagname]) foreach (var item in tagArray) { var tag = FindByName(item); if (tag == null) { tag = new Tag(); tag.Name = item; tag.UserID = userId; tag.PostDateTime = currentDateTime.ToDateTime(); } tag.Count++; tag.FCount++; tag.Save(); var tp = TopicTag.FindByTidAndTagID(topicId, tag.ID); if (tp == null) { tp = new TopicTag(); tp.Tid = topicId; tp.TagID = tag.ID; tp.Insert(); } } }