/// <summary> /// 添加到搜索 /// </summary> public static bool Add(int channel_id, string keyword) { List <Model.search_keys> ls = GetCart(); if (ls != null) { Model.search_keys modelt = ls.Find(p => p.channel_id == channel_id && p.keyword == keyword); if (modelt != null) { int i = ls.FindIndex(p => p.channel_id == channel_id && p.keyword == keyword); ls[i] = modelt; string jsonStr = JsonHelper.ObjectToJSON(ls); //转换为JSON字符串 AddCookies(jsonStr); //重新加入Cookies return(true); } } else { ls = new List <Model.search_keys>(); } //不存在的则新增 ls.Add(new Model.search_keys() { channel_id = channel_id, keyword = keyword }); AddCookies(JsonHelper.ObjectToJSON(ls)); //添加至Cookies return(true); }
/// <summary> /// 移除搜索指定项 /// </summary> public static void Clear(int channel_id, string keyword) { if (channel_id > 0 && keyword != "") { List <Model.search_keys> cartList = GetCart(); if (cartList == null) { return; } Model.search_keys modelt = cartList.Find(p => p.channel_id == channel_id && p.keyword == keyword); if (modelt != null) { cartList.Remove(modelt); //移除指定的项 string jsonStr = JsonHelper.ObjectToJSON(cartList); AddCookies(jsonStr); } } }
/// <summary> /// 转换成List /// </summary> public static List <Model.search_keys> ToList(List <Model.search_keys> ls, int channel_id) { if (ls != null) { List <Model.search_keys> iList = new List <Model.search_keys>(); ls = ls.FindAll(p => p.channel_id == channel_id); foreach (Model.search_keys item in ls) { //开始赋值 Model.search_keys modelt = new Model.search_keys(); modelt.channel_id = item.channel_id; modelt.keyword = item.keyword; //添加入列表 iList.Add(modelt); } return(iList); } return(null); }
/// <summary> /// 移除搜索指定项 /// </summary> public static void Clear(List <Model.search_keys> ls) { if (ls != null) { List <Model.search_keys> cartList = GetCart(); if (cartList == null) { return; } foreach (Model.search_keys modelt in ls) { Model.search_keys model = cartList.Find(p => p.channel_id == modelt.channel_id && p.keyword == modelt.keyword); if (model != null) { cartList.Remove(model); } } string jsonStr = JsonHelper.ObjectToJSON(cartList); AddCookies(jsonStr); } }