示例#1
0
        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);
        }