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(); } } }