Esempio n. 1
0
        //public DataShell<PageShell<UserAccount>> GetPage(PageCondition<UserAccount> userp)
        //{
        //    var res = ReqResTransShell<PageCondition<UserAccount>, PageCondition<UserAccountDBModel>, PageShell<UserAccountDBModel>, PageShell<UserAccount>>(userp, (rq) => _userDAL.GetPage(rq));
        //    return res;
        //}

        //public DataShell<UserAccount> Update(UserAccount user)
        //{
        //    var res = ReqResTransShell<UserAccount, UserAccountDBModel, UserAccountDBModel, UserAccount>(user, (rq) => _userDAL.Update(rq));
        //    return res;
        //}

        //public DataShell<int> Del(UserAccount user)
        //{
        //    var res = ReqResTransShell<UserAccount, UserAccountDBModel, int, int>(user, (rq) => _userDAL.Del(rq));
        //    return res;
        //}

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public IDataShell <AccountModel> Login(AccountModel user)
        {
            #region --提取用户信息--
            IDataShell <AccountDBModel> tempres = new DataShell <AccountDBModel>();
            switch (user)
            {
            case AccountModel u when user.Account.NotNullEmpty():
                tempres = _userDAL.GetByAccount(user);

                break;

            case AccountModel u when user.Email.NotNullEmpty():
                tempres = _userDAL.GetByEmail(user);

                break;

            case AccountModel u when user.Mobile.NotNullEmpty():
                tempres = _userDAL.GetByMobile(user);

                break;

            case AccountModel u when user.AccountID.NotNullEmpty():
                tempres = _userDAL.GetByAccountID(user);

                break;

            default:
                throw new Exception("没有找到匹配的用户");
            }
            if (tempres.Failure)
            {
                return(tempres.ToNewShell <AccountDBModel, AccountModel>());
            }
            #endregion

            #region --密码核验--
            var srcuser   = tempres.Data;
            var verifyRes = PasswordVerify(srcuser.Password, user.Password);
            if (verifyRes.Failure)
            {
                return(verifyRes.Info.Fail <AccountModel>());
            }
            #endregion

            #region --更新登录信息--
            user.LastLoginTime = DateTime.Now;
            user.TotalLoginTimes++;
            var update_res = _userDAL.UpdateAfterLogin(user);
            #endregion

            #region --用户权限--
            #endregion

            var res = user.ToBllModel();

            return(res.Succ());
        }
        public IDataShell <AccountDBModel> GetByMobile(AccountDBModel user)
        {
            var res = _userDAL.GetByMobile(user);

            return(res);
        }