public ReturnResponse<UserInfoViewModels> Login(UserInfoViewModels userInfo)
 {
     var response = new ReturnResponse<UserInfoViewModels>();
     var para = new UserInfoQueryParameter()
     {
         Account = userInfo.Account,
         //Password = userInfo.Password.Md5Compute32(),
         AccountType = userInfo.Account.GetAccountType(),
         Take = 1,
         IsPage = false
     };
     var res = Query(para);
     if (res.IsSuccess && res.Body.Items.Any())
     {
         response.Body = res.Body.Items.FirstOrDefault();
         if (response.Body != null && response.Body.DataStatus == 1)
         {
             response.ResponseCode = 403;
             response.Message = "user has been forbidden";
         }
         else if (response.Body != null && !userInfo.Password.Md5Compute32().Equals(response.Body.Password))
         {
             response.ResponseCode = 400;
             response.Message = "user name or password error";
         }
         else
         {
             response.ResponseCode = 1;
             response.Message = "login success";
         }
     }
     else
     {
         response.ResponseCode = 400;
         response.Message = "user name doesn't exist";
     }
     return response;
 }
Exemple #2
0
        private static void UserInfoRegister()
        {
            var num = Guid.NewGuid().ToString();
            var userInfo = new UserInfoViewModels()
            {
                Account = "1_Unit_Test" + num,
                Password = ("1_Unit_Test" + num),
                CompanyName = "东方航空集团航空公司",
                Address = "上海市长宁区绥宁路388号"
            };

            UserinfoBll.Register(userInfo);
        }
        public ReturnResponse<UserInfoViewModels> Register(UserInfoViewModels userInfo)
        {
            var response = new ReturnResponse<UserInfoViewModels>();
            if (string.IsNullOrWhiteSpace(userInfo.Account))
            {
                response.Body = null;
                response.ResponseCode = 100;
                response.Message = "UserName can't be empty";
                return response;
            }
            if (string.IsNullOrWhiteSpace(userInfo.Password))
            {
                response.Body = null;
                response.ResponseCode = 100;
                response.Message = "UserPWD can't be empty";
                return response;
            }

            var usersRes = Query(new UserInfoQueryParameter() { Account = userInfo.Account,  Take = 1, IsPage = false });

            if (usersRes.ResponseCode == 1 && usersRes.Body.Items.Any())
            {
                response.Body = new UserInfoViewModels();
                response.ResponseCode = 400;
                response.Message = "UserName was exist";
                return response;
            }
            userInfo.Password = userInfo.Password.Md5Compute32();

            using (var trans = new TransactionScope())
            {
                try
                {
                    var resUserInfo = _userInfoDal.Save(new UserInfo()
                    {
                        Password = userInfo.Password,
                        Address = userInfo.Address,
                        CompanyName = userInfo.CompanyName,
                        NickName = userInfo.NickName,
                        Gender = userInfo.Gender,
                        Remark = userInfo.Remark
                    }); //_IContainer.Resolve<IUserDAL>().Save(user);
                    if (resUserInfo.Id > 0)
                    {
                        _userInfoAccountDal.Save(new UserInfoAccount()
                        {
                            UserInfoID = resUserInfo.Id,
                            Account = userInfo.Account,
                            AccountType = userInfo.AccountType
                        });
                        userInfo.Id = resUserInfo.Id;
                        trans.Complete();

                    }
                }
                finally
                {
                    trans.Dispose();
                }
            }
            if (userInfo.Id > 0)
            {
                response.Body = userInfo;
                response.ResponseCode = 1;
                response.Message = "regist success";
            }
            else
            {
                response.Body = userInfo;
                response.ResponseCode = -1;
                response.Message = " Insert failed";
            }
            return response;
        }