/// <summary> /// 添加新的TAG标签 /// </summary> /// <param name="listtag">标签,原始,用“,”隔开的字符串</param> /// <param name="xtypeid">类型</param> /// <param name="rid">目标ID,文章ID,商品ID等...</param> /// <param name="tagtitle">目标标题,文章标题,商品标题等(缓存用的)</param> public static void InsertTags(string listtag, Utils.CMSType xtypeid, int rid, string tagtitle) { //流程:分割TAG,遍历标签;判断是否存在;插入。 //1、分割标签 if (!string.IsNullOrEmpty(listtag)) { string[] arrtags = listtag.Split(new string[] { "," }, StringSplitOptions.None); if (arrtags != null && arrtags.Length > 0) { foreach (string s in arrtags) { //2、单个标签处理 if (!string.IsNullOrEmpty(s) && Utils.GetStringLength(s.Trim()) < 100) { TagsDetail tagsDetail = new TagsDetail(); Tags tmptag = new Tags(); //判断是否存在这个标签 if (FindCount(_.TagName == s.Trim(), null, null, 0, 0) > 0) { tmptag = Find(_.TagName == s.Trim()); //GetModel(s.Trim()); tmptag.Counts = tmptag.Counts + 1; tmptag.Update(); } else { tmptag = new Tags() { AddTime = DateTime.Now, Counts = 1, Description = "", Hits = 0, IsTop = 0, Keywords = "", TagName = s.Trim(), }; tmptag.Insert(); } tagsDetail.RId = rid; tagsDetail.TypeId = xtypeid.ToInt(); tagsDetail.TagName = s.Trim(); tagsDetail.TagsId = tmptag.Id; tagsDetail.Title = tagtitle; tagsDetail.Hits = 0; tagsDetail.AddTime = DateTime.Now; tagsDetail.Insert(); } } } } }
/// <summary> /// 编辑Tag标签 /// </summary> /// <param name="listtag">标签,原始,用“,”隔开的字符串</param> /// <param name="xtypeid">类型</param> /// <param name="rid">目标ID,文章ID,商品ID等...</param> /// <param name="tagtitle">目标标题,文章标题,商品标题等(缓存用的)</param> public static void ModifyTags(string listtag, Utils.CMSType xtypeid, int rid, string tagtitle) { IList <TagsDetail> listdetail = TagsDetail.FindAll(TagsDetail._.RId == rid & TagsDetail._.TypeId == (int)xtypeid, null, null, 0, 0); if (!string.IsNullOrEmpty(listtag)) { string[] arrtags = listtag.Split(new string[] { "," }, StringSplitOptions.None); if (arrtags != null && arrtags.Length > 0) { foreach (string s in arrtags) { //2、单个标签处理 只有 添加或者 删除。没有修改的 if (!string.IsNullOrEmpty(s) && Utils.GetStringLength(s.Trim()) < 100) { //判断是否存在 var td = listdetail.Find(x => x.TagName == s.Trim()); if (td == null) { TagsDetail tagsDetail = new TagsDetail(); Tags tmptag = new Tags(); //判断是否存在这个标签 if (FindCount(_.TagName == s.Trim(), null, null, 0, 0) > 0) { tmptag = Find(_.TagName == s.Trim()); //GetModel(s.Trim()); tmptag.Counts = tmptag.Counts + 1; tmptag.Update(); } else { tmptag = new Tags() { AddTime = DateTime.Now, Counts = 1, Description = "", Hits = 0, IsTop = 0, Keywords = "", TagName = s.Trim(), }; tmptag.Insert(); } tagsDetail.RId = rid; tagsDetail.TypeId = xtypeid.ToInt(); tagsDetail.TagName = s.Trim(); tagsDetail.TagsId = tmptag.Id; tagsDetail.Title = tagtitle; tagsDetail.Hits = 0; tagsDetail.AddTime = DateTime.Now; tagsDetail.Insert(); } else { listdetail.Remove(td); var tmptag = Find(_.TagName == s.Trim()); if (tmptag != null) { long counts = TagsDetail.FindCount(TagsDetail._.TagName == s.Trim(), null, null, 0, 0); if (counts == 0) { tmptag.Delete(); } else { tmptag.Counts = (int)counts; tmptag.Update(); } } } } } } } }