Ejemplo n.º 1
0
 private object GetValue(Type type, object value)
 {
     if (type.IsPrimitive)
     {
         return(GetPrimitiveValue(type, value));
     }
     else if (Nullable.GetUnderlyingType(type) != null) //if we're nullable, id say call the getvalue method again on the underlying type
     {
         var t = Nullable.GetUnderlyingType(type);
         return(GetValue(t, value));
     }
     else if (type == typeof(string))
     {
         return(value.ToString());
     }
     else if (type.IsEnum)
     {
         return(ConvertExtensions.ToEnum <XmlEnumAttribute>(value.ToString(), type));
     }
     else if (type == typeof(DateTime))
     {
         return(DateTime.Parse(value.ToString()));
     }
     else if (type == typeof(TimeSpan))
     {
         return(ConvertExtensions.ToTimeSpan(value.ToString()));
     }
     return(null);
 }
Ejemplo n.º 2
0
        public CustomMessage UserLogin(string userName, string userPwd)
        {
            var message = new CustomMessage();

            try
            {
                var dbContext = DbContainer.GetDbContext();

                userPwd = MD5Helper.Encry(userPwd);
                var query = (from u in dbContext.UserInfo
                             where u.UserName == userName && u.UserPwd == userPwd
                             select u).ToList();

                if (query.Count() == 0)
                {
                    message.Status  = HttpStatus.Error;
                    message.Message = "用户名或密码错误!";
                }
                else
                {
                    Data.UserInfo user = query[0];

                    if (user.IsActivation == null)
                    {
                        message.Status  = HttpStatus.Error;
                        message.Message = "当前账户还未激活!";
                    }
                    else
                    {
                        // 计算剩余时间
                        var remainingSeconds = (DateTime.Now - ConvertExtensions.ToTimeSpan((int)user.ActivationLevel, (DateTime)user.ActivationDate)).TotalSeconds;

                        message.Status  = HttpStatus.OK;
                        message.Message = new
                        {
                            RemainingSeconds = remainingSeconds,
                            Info             = "登陆成功!"
                        };
                    }
                }
            }
            catch (Exception objException)
            {
                LogHelper.Error(objException);
                message.Status  = HttpStatus.Error;
                message.Message = objException.Message;
            }

            return(message);
        }