Esempio n. 1
0
        /// <summary>
        /// 检查用户在登陆表中的情况,返回bool和返回信息。
        /// </summary>
        /// <param name="user"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static bool CheckStatus(UserInfo user, out string message)
        {
            //用户不存在
            if (user == null)
            {
                message = Conf.MessageInfo.USER_NOT_EXIST;
                return(false);
            }
            IEnumerable <UserPersistence> set = list.Where(i => i.Uid == user.ID);

            //未登陆
            if (set == null || !set.Any())
            {
                message = Conf.MessageInfo.USER_NOT_LOGEDIN;
                return(false);
            }
            UserPersistence u = set.First();
            //登陆超时
            //if (u.LoginTime.AddMinutes(Conf.Config.LOGIN_EFFECTIVE_MINUTE) < DateTime.Now)
            //{
            //    message = Conf.MessageInfo.LOGIN_TIMEOUT;
            //    return false;
            //}
            //已登陆,更新登陆状态。
            UserPersistence newStatus = new UserPersistence
            {
                Uid       = u.Uid,
                LoginTime = DateTime.Now
            };

            list.Remove(u);
            list.Add(newStatus);
            message = Conf.MessageInfo.LOGIN_OK;
            return(true);
        }
Esempio n. 2
0
 public static bool remove(int uid)
 {
     try
     {
         UserPersistence current = list.Find(u => u.Uid == uid);
         if (current != null)
         {
             list.Remove(current);
         }
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 3
0
        public static bool Add(UserInfo user)
        {
            IEnumerable <UserPersistence> set = from up in list where up.Uid == user.ID select up;

            //登陆状态不存在(直接添加状态)
            if (!set.Any())
            {
                UserPersistence newUser = new UserPersistence
                {
                    Uid       = user.ID,
                    LoginTime = DateTime.Now
                };
                list.Add(newUser);
                return(true);
            }
            //登陆状态存在(Update一下登陆时间)
            else
            {
                UserPersistence current = list.Find(u => u.Uid == user.ID);
                current.LoginTime = DateTime.Now;
                return(true);
            }
        }