Beispiel #1
0
        /// <summary>
        /// 删除搜索历史记录
        /// </summary>
        public ApiResult DeleteHistory(int uid, int lType, long userId)
        {
            string memberKey = string.Format(RedisKeyConst.Plan_ExpertHistory, lType, userId);//"history_" + userId + "_" + lType;
            List <ExpertSearchModel> list = CacheHelper.GetCache <List <ExpertSearchModel> >(memberKey);

            if (uid > 0)
            {
                ExpertSearchModel e1 = list.Where(x => x.UserId == uid && x.lType == lType).FirstOrDefault();
                list.Remove(e1);
                //CacheHelper.WriteCache(memberKey, list, 144000);
                CacheHelper.AddCache(memberKey, list, 144000);
            }
            else
            {
                CacheHelper.DeleteCache(memberKey);
            }
            return(new ApiResult());
        }
Beispiel #2
0
        /// <summary>
        /// 插入搜索数据
        /// </summary>
        public ApiResult InsertHotSearch(long uid, int lType, long userId)
        {
            //ReturnMessageJson msg = new ReturnMessageJson();
            string countsql = string.Format("select count(1) from ExpertHotSearch where UserId ={0} and lType = {1}", uid, lType);
            int    count    = Convert.ToInt32(SqlHelper.ExecuteScalar(countsql));
            string strsql   = "";

            if (count > 0)
            {
                strsql = @"update ExpertHotSearch  set Count=Count+1 where UserId=@UserId and lType=@lType ";
            }
            else
            {
                strsql = @"insert into ExpertHotSearch(UserId, Count, lType)
                           values(@UserId,1,@lType)";
            }
            SqlParameter[] sp = new SqlParameter[] {
                new SqlParameter("@UserId", uid),
                new SqlParameter("@lType", lType)
            };

            int data = SqlHelper.ExecuteNonQuery(strsql, sp);

            if (data > 0)
            {
                List <ExpertSearchModel> list = new List <ExpertSearchModel>();

                long   MyUserId  = userId;
                string memberKey = string.Format(RedisKeyConst.Plan_ExpertHistory, lType, MyUserId);// "history_" + MyUserId + "_" + lType;
                list = CacheHelper.GetCache <List <ExpertSearchModel> >(memberKey) ?? new List <ExpertSearchModel>();

                UserInfo u = PersonalService.GetUser(uid);

                ExpertSearchModel e = new ExpertSearchModel();
                e.Avater   = u.Avater;
                e.UserId   = (int)uid;
                e.Name     = u.NickName;
                e.lType    = lType;
                e.isFollow = 0;
                if (list.Count > 0)
                {
                    ExpertSearchModel e1 = list.Where(x => x.UserId == uid && x.lType == lType).FirstOrDefault();
                    if (e1 == null)
                    {
                        list.Add(e);
                    }
                }
                else
                {
                    list.Add(e);
                }

                // CacheHelper.WriteCache(memberKey, list, 144000);
                CacheHelper.AddCache(memberKey, list, 144000);
                return(new ApiResult());
            }
            else
            {
                return(new ApiResult(-999, "数据库错误"));
            }
        }