示例#1
0
        public async Task LoginAsyncSignInSuccessedCreateJwtToken(UserTypeEnum userType)
        {
            var command = new LoginUserCommand()
            {
                Email    = _faker.Person.Email,
                Password = _faker.Internet.Password(),
                TokenId  = _faker.Random.Guid()
            };

            var userName = UserHelper.GetUserName(userType, command.Email);

            var user = new User()
            {
                Id = 1
            };

            var jwtToken = "";

            _userManagerMock.Setup(x => x.FindByNameAsync(userName)).ReturnsAsync(user);
            _signInManagerMock.Setup(x => x.PasswordSignInAsync(user, command.Password, false, false)).ReturnsAsync(SignInResult.Success);
            _jwtHandlerMock.Setup(x => x.CreateToken(user.Id, userType.ToString())).Returns(jwtToken);

            var err = await Record.ExceptionAsync(async() => await _userService.LoginAsync(userType, command));

            err.Should().BeNull();

            _signInManagerMock.Verify(x => x.PasswordSignInAsync(user, command.Password, false, false), Times.Once);
            _jwtHandlerMock.Verify(x => x.CreateToken(user.Id, userType.ToString()), Times.Once);
        }
        public async Task <int> GetTagIdAsync(UserTypeEnum typeSCode)
        {
            int    tagId   = 0;
            string tagName = "";
            //var fans1 = await UserTagApi.UserTagListAsync(AppConfig.AppId, "oPM5Uv81jfyJqWbVxWAH-RUqsCAs");

            var tags = await UserTagApi.GetAsync(AppConfig.AppId);

            var groupSe = await _wechatgroupRepository.GetAll().Where(G => G.TypeName == typeSCode.ToString()).FirstOrDefaultAsync();

            foreach (var item in tags.tags)
            {
                if (item.name == typeSCode.ToString())
                {
                    tagId   = item.id;
                    tagName = item.name;
                }
            }
            if (string.IsNullOrEmpty(tagName))
            {
                var result = await UserTagApi.CreateAsync(AppConfig.AppId, typeSCode.ToString());

                if (groupSe == null)
                {
                    WeChatGroupListDto group = new WeChatGroupListDto();
                    if (result.errcode == 0)
                    {
                        group.TagId    = result.tag.id;
                        group.TagName  = result.tag.name;
                        group.TypeName = typeSCode.ToString();
                        group.TypeCode = typeSCode;
                        await CreateWeChatGroupAsync(group.MapTo <WeChatGroupEditDto>());
                    }
                }
                return(result.tag.id);
            }
            else
            {
                if (groupSe == null)
                {
                    WeChatGroupListDto group = new WeChatGroupListDto();
                    group.TagId    = tagId;
                    group.TagName  = tagName;
                    group.TypeName = typeSCode.ToString();
                    group.TypeCode = typeSCode;
                    await CreateWeChatGroupAsync(group.MapTo <WeChatGroupEditDto>());
                }
                return(tagId);
            }
        }
        // ####################################################################################
        // Create user
        // ####################################################################################
        public User GetOrCreateTestUser(DPOContext context, Group group, Business business, string name, UserTypeEnum userType, bool approved, bool isGroupOwner)
        {
            string email = string.Format("{0}@somewhere.com", name);

            var user = Db.UserQueryByEmail(email).FirstOrDefault();

            if (user == null)
            {
                user = Db.UserCreate(business, group, userType);

                user.FirstName          = name;
                user.LastName           = userType.ToString();;
                user.RegisteredOn       = DateTime.Now;
                user.Email              = email;
                user.Salt               = 234544543;
                user.Password           = Crypto.Hash("test", 234544543);
                user.LastLoginOn        = DateTime.Now;
                user.UseBusinessAddress = true;
                user.IsGroupOwner       = isGroupOwner;
                if (approved)
                {
                    user.Approved   = true;
                    user.ApprovedOn = DateTime.Now;
                    user.Enabled    = true;
                }

                // Add all permissions to user
                Db.CopyPermissions(EntityEnum.Business, business.BusinessId, EntityEnum.User, user.UserId);

                Db.CopyPermissions(EntityEnum.UserType, (long)userType, EntityEnum.User, user.UserId);
            }
            return(user);
        }
示例#4
0
 public static string GetEnumDisplayName(this UserTypeEnum userTypeEnum)
 {
     return(userTypeEnum.GetType().GetMember(userTypeEnum.ToString())
            .First()
            .GetCustomAttribute <DisplayAttribute>()
            .Name);
 }
        public async Task RegisterAsync(UserTypeEnum userType, CreateUserCommand command)
        {
            var user = new User
            {
                Name           = command.FirstName,
                UserName       = UserHelper.GetUserName(userType, command.Email),
                Surname        = command.LastName,
                Degree         = command.AcademicTitle,
                Email          = command.Email,
                Specialization = command.Specialization,
                University     = command.University
            };

            // only participant have avatar
            if (userType == UserTypeEnum.Participant)
            {
                user.Photo = await _fileManager.SaveFileAsync(command.Avatar);
            }

            var createUserResult = await _userManager.CreateAsync(user, command.Password);

            if (createUserResult.Succeeded)
            {
                await _userManager.AddToRoleAsync(user, userType.ToString());

                var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                await _emailSender.SendConfirmationEmailAsync(user.Id, user.Email, token);
            }
        }
示例#6
0
 public static string ToDescriptionString(this UserTypeEnum val)
 {
     DescriptionAttribute[] attributes = (DescriptionAttribute[])val
                                         .GetType()
                                         .GetField(val.ToString())
                                         .GetCustomAttributes(typeof(DescriptionAttribute), false);
     return(attributes.Length > 0 ? attributes[0].Description : string.Empty);
 }
示例#7
0
 public static User ToUserExtension(this AuthenticationRequest request, UserTypeEnum userType)
 {
     return(new User
     {
         Username = request.Username,
         Password = request.Password,
         Type = userType.ToString()
     });
 }
示例#8
0
 public static User ToUser(AuthenticationRequest request, UserTypeEnum userType)
 {
     return(new User
     {
         username = request.username,
         password = request.password,
         Type = userType.ToString()
     });
 }
示例#9
0
 public static Client ToUserExtension(this AuthenticationRequest request, UserTypeEnum userType)
 {
     return(new Client
     {
         Email = request.Email,
         Password = request.Password,
         Type = userType.ToString()
     });
 }
示例#10
0
        public async Task RegisterAsyncRegisterSuccesfullySendEmailConfirmation(UserTypeEnum userType)
        {
            var command = new CreateUserCommand()
            {
                FirstName      = _faker.Person.FirstName,
                LastName       = _faker.Person.LastName,
                AcademicTitle  = _faker.Name.JobTitle(),
                Email          = _faker.Person.Email,
                Specialization = _faker.Commerce.Categories(1)[0],
                University     = _faker.Company.CompanyName(),
                Password       = _faker.Internet.Password()
            };

            var user = new User
            {
                Id             = 0,
                Name           = command.FirstName,
                UserName       = UserHelper.GetUserName(userType, command.Email),
                Surname        = command.LastName,
                Degree         = command.AcademicTitle,
                Email          = command.Email,
                Specialization = command.Specialization,
                University     = command.University
            };

            var token = _faker.Random.String(10);

            _userManagerMock.Setup(x => x.CreateAsync(It.IsAny <User>(), command.Password)).ReturnsAsync(IdentityResult.Success);
            _userManagerMock.Setup(x => x.AddToRoleAsync(It.IsAny <User>(), userType.ToString()));
            _userManagerMock.Setup(x => x.GenerateEmailConfirmationTokenAsync(It.IsAny <User>())).ReturnsAsync(token);

            _emailSendeMock.Setup(x => x.SendConfirmationEmailAsync(user.Id, user.Email, token));

            var err = await Record.ExceptionAsync(async() => await _userService.RegisterAsync(userType, command));

            err.Should().BeNull();

            _userManagerMock.Verify(x => x.CreateAsync(It.Is <User>(x => x.Id == user.Id && x.UserName == user.UserName), command.Password), Times.Once);
            _userManagerMock.Verify(x => x.AddToRoleAsync(It.Is <User>(x => x.Id == user.Id && x.UserName == user.UserName), userType.ToString()), Times.Once);
            _userManagerMock.Verify(x => x.GenerateEmailConfirmationTokenAsync(It.Is <User>(x => x.Id == user.Id && x.UserName == user.UserName)), Times.Once);

            _emailSendeMock.Verify(x => x.SendConfirmationEmailAsync(user.Id, user.Email, token), Times.Once);
        }
示例#11
0
        public async Task LoginAsync(UserTypeEnum userType, LoginUserCommand request)
        {
            var userName = UserHelper.GetUserName(userType, request.Email);

            var user = await _userManager.FindByNameAsync(userName);

            if (user is null)
            {
                throw new Exception("Invalid credentials");
            }

            var result = await _signInManager.PasswordSignInAsync(user, request.Password, false, false);

            if (result.Succeeded)
            {
                // return login/JWT token
                var jwtToken = _jwtHandler.CreateToken(user.Id, userType.ToString());
                _cache.SetJwt(request.TokenId, jwtToken);
            }
        }
示例#12
0
        void Save()
        {
            List <UsersUpdateLog> updateList = new List <UsersUpdateLog>();

            string userName = this.txtuserName.Text;
            string password = this.txtpassword.Text;
            int    CPSDrate = 0;

            int.TryParse(this.txtCPSDrate.Text, out CPSDrate);
            int CVSNrate = 0;

            int.TryParse(this.txtCVSNrate.Text, out CVSNrate);
            string email  = this.txtemail.Text;
            string qq     = this.txtqq.Text;
            string tel    = this.txttel.Text;
            string idCard = this.txtidCard.Text;
            int    pmode  = 0;

            int.TryParse(this.rblsettlemode.SelectedValue, out pmode);

            string payeeName    = this.txtpayeeName.Text;
            string payeeBank    = this.txtpayeeBank.Text;
            string bankProvince = this.txtbankProvince.Text;
            string bankCity     = this.txtbankCity.Text;
            string bankAddress  = this.txtbankAddress.Text;
            int    status       = int.Parse(ddlStatus.SelectedValue);

            model.classid = int.Parse(rbuserclass.SelectedValue);
            //string company = this.txtcompany.Text;
            //string linkMan = this.txtlinkMan.Text;
            string       account   = this.txtaccount.Text;
            string       siteName  = this.txtsiteName.Text;
            string       siteUrl   = this.txtsiteUrl.Text;
            UserTypeEnum userType  = (UserTypeEnum)int.Parse(rbluserType.SelectedValue);
            int          userLevel = 0;

            if (userType == UserTypeEnum.会员)
            {
                userLevel = int.Parse(this.ddlmemvip.SelectedValue);
            }
            else if (userType == UserTypeEnum.代理)
            {
                userLevel = int.Parse(this.ddlpromvip.SelectedValue);
            }

            //int maxdaytocashTimes = int.Parse(this.txtmaxdaytocashTimes.Text);
            string apikey = this.txtapikey.Text;

            //if (isUpdate && userName != model.UserName)
            //{

            //}
            model.UserName     = userName;
            model.APIAccount   = int.Parse(this.txtapiAcct.Text);
            model.Settles      = Convert.ToInt32(rbl_settledmode.SelectedValue);
            model.smsNotifyUrl = this.txtsmsNotifyUrl.Text;
            //model.classid

            if (!string.IsNullOrEmpty(password))
            {
                password = viviLib.Security.Cryptography.MD5(password);
                if (isUpdate && password != model.Password)
                {
                    updateList.Add(newUpdateLog("password", password, model.Password));
                }
                model.Password = password;
            }
            if (!string.IsNullOrEmpty(this.txtpassword2.Text.Trim()))
            {
                string password2 = viviLib.Security.Cryptography.MD5(this.txtpassword2.Text.Trim());
                //if (isUpdate && password != model.Password)
                //{
                //    updateList.Add(newUpdateLog("password", password, model.Password));
                //}
                model.Password2 = password2;
            }
            if (isUpdate && CPSDrate != model.CPSDrate)
            {
                updateList.Add(newUpdateLog("CPSDrate", CPSDrate.ToString(), model.CPSDrate.ToString()));
            }
            model.CPSDrate = CPSDrate;

            if (isUpdate && CVSNrate != model.CVSNrate)
            {
                updateList.Add(newUpdateLog("CVSNrate", CVSNrate.ToString(), model.CVSNrate.ToString()));
            }
            model.CVSNrate = CVSNrate;

            if (isUpdate && email != model.Email)
            {
                updateList.Add(newUpdateLog("Email", email, model.Email));
            }
            model.Email = email;

            if (isUpdate && qq != model.QQ)
            {
                updateList.Add(newUpdateLog("QQ", qq, model.QQ));
            }
            model.QQ = qq;

            if (isUpdate && tel != model.Tel)
            {
                updateList.Add(newUpdateLog("tel", tel, model.Tel));
            }
            model.Tel = tel;

            if (isUpdate && idCard != model.IdCard)
            {
                updateList.Add(newUpdateLog("idCard", idCard, model.IdCard));
            }
            model.IdCard = idCard;

            //收款
            if (isUpdate && pmode != model.PMode)
            {
                updateList.Add(newUpdateLog("pmode", pmode.ToString(), model.PMode.ToString()));
            }
            model.PMode = pmode;

            if (isUpdate && account != model.Account)
            {
                updateList.Add(newUpdateLog("account", account, model.Account));
            }
            model.Account = account;

            if (isUpdate && payeeName != model.PayeeName)
            {
                updateList.Add(newUpdateLog("payeeName", payeeName, model.PayeeName));
            }
            model.PayeeName = payeeName;

            if (isUpdate && payeeBank != model.PayeeBank)
            {
                updateList.Add(newUpdateLog("payeeBank", payeeBank, model.PayeeBank));
            }
            model.PayeeBank = payeeBank;

            if (isUpdate && bankProvince != model.BankProvince)
            {
                updateList.Add(newUpdateLog("BankProvince", bankProvince, model.BankProvince));
            }
            model.BankProvince = bankProvince;

            if (isUpdate && bankCity != model.BankCity)
            {
                updateList.Add(newUpdateLog("BankCity", bankCity, model.BankCity));
            }
            model.BankCity = bankCity;

            if (isUpdate && bankAddress != model.BankAddress)
            {
                updateList.Add(newUpdateLog("bankAddress", bankAddress, model.BankAddress));
            }
            model.BankAddress = bankAddress;

            if (isUpdate && status != model.Status)
            {
                updateList.Add(newUpdateLog("status", status.ToString(), model.Status.ToString()));
            }
            model.Status = status;

            //model.company = company;
            //model.linkMan = linkMan;
            if (isUpdate && siteName != model.SiteName)
            {
                updateList.Add(newUpdateLog("SiteName", siteName, model.SiteName));
            }
            model.SiteName = siteName;

            if (isUpdate && siteUrl != model.SiteUrl)
            {
                updateList.Add(newUpdateLog("siteUrl", siteUrl, model.SiteUrl));
            }
            model.SiteUrl = siteUrl;

            if (isUpdate && userType != model.UserType)
            {
                updateList.Add(newUpdateLog("userType", userType.ToString(), ((int)model.UserType).ToString()));
            }
            model.UserType = (UserTypeEnum)userType;

            if (isUpdate && userLevel != (int)model.UserLevel)
            {
                updateList.Add(newUpdateLog("userLevel", userLevel.ToString(), ((int)model.UserLevel).ToString()));
            }
            model.UserLevel = userLevel;


            //if (isUpdate && maxdaytocashTimes != model.MaxDayToCashTimes)
            //{
            //    updateList.Add(newUpdateLog("MaxDayToCashTimes", maxdaytocashTimes.ToString(), model.MaxDayToCashTimes.ToString()));
            //}
            //model.MaxDayToCashTimes = maxdaytocashTimes;

            int maxdaytocashTimes = 0;

            if (!string.IsNullOrEmpty(ddlTocashScheme.SelectedValue))
            {
                maxdaytocashTimes = int.Parse(this.ddlTocashScheme.SelectedValue);
            }
            if (isUpdate && maxdaytocashTimes != model.MaxDayToCashTimes)
            {
                updateList.Add(newUpdateLog("MaxDayToCashTimes", maxdaytocashTimes.ToString(), model.MaxDayToCashTimes.ToString()));
            }
            model.MaxDayToCashTimes = maxdaytocashTimes;

            if (isUpdate && apikey != model.APIKey)
            {
                updateList.Add(newUpdateLog("APIKey", apikey, model.APIKey));
            }
            model.APIKey         = apikey;
            model.Desc           = this.txtdesc.Text;
            model.IsRealNamePass = cb_isRealNamePass.Checked ? 1 : 0;
            model.IsEmailPass    = cb_isEmailPass.Checked ? 1 : 0;
            model.IsPhonePass    = cb_isPhonePass.Checked ? 1 : 0;

            model.isdebug = cb_isdebug.Checked ? 1 : 0;
            if (!string.IsNullOrEmpty(ddlmange.SelectedValue))
            {
                model.manageId = int.Parse(ddlmange.SelectedValue);
            }

            // model.IdCardType = 1;

            if (!this.isUpdate)
            {
                int id = Factory.Add(model);
                if (id > 0)
                {
                    AlertAndRedirect("保存成功!", "UserList.aspx");
                }
                else
                {
                    AlertAndRedirect("保存失败!");
                }
            }
            else
            {
                if (Factory.Update(model, updateList))
                {
                    AlertAndRedirect("更新成功!", "UserList.aspx");
                }
                else
                {
                    AlertAndRedirect("更新失败!");
                }
            }
        }
示例#13
0
 private UserType(UserTypeEnum @enum)
 {
     Id   = (int)@enum;
     Name = @enum.ToString();
 }
示例#14
0
        void Save()
        {
            var updateList = new List <UsersUpdateLog>();

            string userName = this.txtuserName.Text;
            string password = this.txtpassword.Text;
            int    CPSDrate = 0;

            int.TryParse(this.txtCPSDrate.Text, out CPSDrate);
            int CVSNrate = 0;

            int.TryParse(this.txtCVSNrate.Text, out CVSNrate);
            string email  = this.txtemail.Text;
            string qq     = this.txtqq.Text;
            string tel    = this.txttel.Text;
            string idCard = this.txtidCard.Text;
            int    pmode  = 0;

            int.TryParse(this.rblsettlemode.SelectedValue, out pmode);

            string payeeName = this.txtpayeeName.Text;

            int status = int.Parse(ddlStatus.SelectedValue);

            model.classid = int.Parse(rbuserclass.SelectedValue);
            //string company = this.txtcompany.Text;
            //string linkMan = this.txtlinkMan.Text;
            string       account   = this.txtaccount.Text;
            string       siteName  = this.txtsiteName.Text;
            string       siteUrl   = this.txtsiteUrl.Text;
            UserTypeEnum userType  = (UserTypeEnum)int.Parse(rbluserType.SelectedValue);
            int          userLevel = 0;

            userLevel = int.Parse(this.ddlUserLevel.SelectedValue);

            //int maxdaytocashTimes = int.Parse(this.txtmaxdaytocashTimes.Text);
            string apikey = this.txtapikey.Text;

            //if (isUpdate && userName != model.UserName)
            //{

            //}
            model.UserName     = userName;
            model.APIAccount   = int.Parse(this.txtapiAcct.Text);
            model.Settles      = Convert.ToInt32(rbl_settledmode.SelectedValue);
            model.smsNotifyUrl = this.txtsmsNotifyUrl.Text;
            //model.classid

            if (!string.IsNullOrEmpty(password))
            {
                password = viviLib.Security.Cryptography.MD5(password);
                if (isUpdate && password != model.Password)
                {
                    updateList.Add(NewUpdateLog("password", password, model.Password));
                }
                model.Password = password;
            }
            if (!string.IsNullOrEmpty(this.txtpassword2.Text.Trim()))
            {
                string password2 = viviLib.Security.Cryptography.MD5(this.txtpassword2.Text.Trim());
                //if (isUpdate && password != model.Password)
                //{
                //    updateList.Add(newUpdateLog("password", password, model.Password));
                //}
                model.Password2 = password2;
            }
            if (isUpdate && CPSDrate != model.CPSDrate)
            {
                updateList.Add(NewUpdateLog("CPSDrate", CPSDrate.ToString(), model.CPSDrate.ToString()));
            }
            model.CPSDrate = CPSDrate;

            if (isUpdate && CVSNrate != model.CVSNrate)
            {
                updateList.Add(NewUpdateLog("CVSNrate", CVSNrate.ToString(), model.CVSNrate.ToString()));
            }
            model.CVSNrate = CVSNrate;

            if (isUpdate && email != model.Email)
            {
                updateList.Add(NewUpdateLog("Email", email, model.Email));
            }
            model.Email = email;

            if (isUpdate && qq != model.QQ)
            {
                updateList.Add(NewUpdateLog("QQ", qq, model.QQ));
            }
            model.QQ = qq;

            if (isUpdate && tel != model.Tel)
            {
                updateList.Add(NewUpdateLog("tel", tel, model.Tel));
            }
            model.Tel = tel;

            if (isUpdate && idCard != model.IdCard)
            {
                updateList.Add(NewUpdateLog("idCard", idCard, model.IdCard));
            }
            model.IdCard = idCard;

            //收款
            if (isUpdate && pmode != model.PMode)
            {
                updateList.Add(NewUpdateLog("pmode", pmode.ToString(), model.PMode.ToString()));
            }
            model.PMode = pmode;

            if (isUpdate && account != model.Account)
            {
                updateList.Add(NewUpdateLog("account", account, model.Account));
            }
            model.Account = account;

            if (isUpdate && payeeName != model.PayeeName)
            {
                updateList.Add(NewUpdateLog("payeeName", payeeName, model.PayeeName));
            }
            model.PayeeName  = payeeName;
            model.accoutType = int.Parse(rblaccoutType.SelectedValue);

            #region payeeBank
            string bankCode  = this.ddlpayeeBank.SelectedValue;
            string payeeBank = "";

            string provinceCode = "";
            string bankProvince = "";

            string cityCode = "";
            string bankCity = "";

            string bankAddress = this.txtbankAddress.Text;
            if (pmode == 1)
            {
                if (!string.IsNullOrEmpty(bankCode))
                {
                    payeeBank = ddlpayeeBank.Items[ddlpayeeBank.SelectedIndex].Text;
                }
                provinceCode = this.ddlprovince.SelectedValue;
                if (!string.IsNullOrEmpty(provinceCode))
                {
                    bankProvince = ddlprovince.Items[ddlprovince.SelectedIndex].Text;
                }

                cityCode = this.ddlcity.SelectedValue;
                if (!string.IsNullOrEmpty(cityCode))
                {
                    bankCity = ddlcity.Items[ddlcity.SelectedIndex].Text;
                }
            }
            else if (pmode == 2)
            {
                bankCode  = "0002";
                payeeBank = "支付宝";
            }
            else if (pmode == 3)
            {
                bankCode  = "0003";
                payeeBank = "财付通";
            }
            if (isUpdate && bankCode != model.BankCode)
            {
                updateList.Add(NewUpdateLog("bankCode", bankCode, model.BankCode));
            }
            if (isUpdate && payeeBank != model.PayeeBank)
            {
                updateList.Add(NewUpdateLog("payeeBank", payeeBank, model.PayeeBank));
            }
            if (isUpdate && bankProvince != model.BankProvince)
            {
                updateList.Add(NewUpdateLog("BankProvince", bankProvince, model.BankProvince));
            }
            if (isUpdate && bankCity != model.BankCity)
            {
                updateList.Add(NewUpdateLog("BankCity", bankCity, model.BankCity));
            }

            if (isUpdate && bankAddress != model.BankAddress)
            {
                updateList.Add(NewUpdateLog("bankAddress", bankAddress, model.BankAddress));
            }

            model.BankCode     = bankCode;
            model.PayeeBank    = payeeBank;
            model.provinceCode = provinceCode;
            model.BankProvince = bankProvince;
            model.cityCode     = cityCode;
            model.BankCity     = bankCity;

            model.BankAddress = bankAddress;
            #endregion

            if (isUpdate && status != model.Status)
            {
                updateList.Add(NewUpdateLog("status", status.ToString(), model.Status.ToString()));
            }
            model.Status = status;

            //model.company = company;
            //model.linkMan = linkMan;
            if (isUpdate && siteName != model.SiteName)
            {
                updateList.Add(NewUpdateLog("SiteName", siteName, model.SiteName));
            }
            model.SiteName = siteName;

            if (isUpdate && siteUrl != model.SiteUrl)
            {
                updateList.Add(NewUpdateLog("siteUrl", siteUrl, model.SiteUrl));
            }
            model.SiteUrl = siteUrl;

            if (isUpdate && userType != model.UserType)
            {
                updateList.Add(NewUpdateLog("userType", userType.ToString(), ((int)model.UserType).ToString()));
            }
            model.UserType = (UserTypeEnum)userType;

            if (isUpdate && userLevel != (int)model.UserLevel)
            {
                updateList.Add(NewUpdateLog("userLevel", userLevel.ToString(), ((int)model.UserLevel).ToString()));
            }
            model.UserLevel = userLevel;


            //if (isUpdate && maxdaytocashTimes != model.MaxDayToCashTimes)
            //{
            //    updateList.Add(newUpdateLog("MaxDayToCashTimes", maxdaytocashTimes.ToString(), model.MaxDayToCashTimes.ToString()));
            //}
            //model.MaxDayToCashTimes = maxdaytocashTimes;

            int maxdaytocashTimes = 0;
            if (!string.IsNullOrEmpty(ddlTocashScheme.SelectedValue))
            {
                maxdaytocashTimes = int.Parse(this.ddlTocashScheme.SelectedValue);
            }
            model.MaxDayToCashTimes = maxdaytocashTimes;
            if (isUpdate && maxdaytocashTimes != model.MaxDayToCashTimes)
            {
                updateList.Add(NewUpdateLog("MaxDayToCashTimes", maxdaytocashTimes.ToString(), model.MaxDayToCashTimes.ToString()));
            }


            int agentDistscheme = 0;
            if (!string.IsNullOrEmpty(this.ddlagentDistscheme.SelectedValue))
            {
                agentDistscheme = int.Parse(this.ddlagentDistscheme.SelectedValue);
            }
            model.agentDistscheme = agentDistscheme;


            if (isUpdate && apikey != model.APIKey)
            {
                updateList.Add(NewUpdateLog("APIKey", apikey, model.APIKey));
            }
            model.APIKey              = apikey;
            model.Desc                = this.txtdesc.Text;
            model.IsRealNamePass      = cb_isRealNamePass.Checked ? 1 : 0;
            model.IsEmailPass         = cb_isEmailPass.Checked ? 1 : 0;
            model.IsPhonePass         = cb_isPhonePass.Checked ? 1 : 0;
            model.isagentDistribution = cb_isagentDistribution.Checked ? 1 : 0;

            model.isdebug = cb_isdebug.Checked ? 1 : 0;
            if (!string.IsNullOrEmpty(ddlmange.SelectedValue))
            {
                model.manageId = int.Parse(ddlmange.SelectedValue);
            }
            else
            {
                model.manageId = 0;
            }
            model.cardversion = byte.Parse(ddlcardversion.SelectedValue);

            model.province = this.txtProvince.Text.Trim();
            model.city     = this.txtCity.Text.Trim();

            // model.IdCardType = 1;
            int result = 0;
            if (!this.isUpdate)
            {
                int id = Factory.Add(model);
                if (id > 0)
                {
                    setting.userid = id;
                    result         = id;
                    AlertAndRedirect("保存成功!", "UserList.aspx");
                }
                else
                {
                    AlertAndRedirect("保存失败!");
                }
            }
            else
            {
                if (Factory.Update(model, updateList))
                {
                    result = ItemInfoId;


                    AlertAndRedirect("更新成功!", "UserList.aspx");
                }
                else
                {
                    AlertAndRedirect("更新失败!");
                }
            }

            if (result > 0)
            {
                if (!string.IsNullOrEmpty(this.ddlagents.SelectedValue))
                {
                    var promUser = new Promoter
                    {
                        PID        = int.Parse(this.ddlagents.SelectedValue),
                        Prices     = 0.5M,
                        RegId      = result,
                        PromTime   = DateTime.Now,
                        PromStatus = 1
                    };

                    viviapi.BLL.Promotion.Factory.Insert(promUser);
                }
                else
                {
                    viviapi.BLL.Promotion.Factory.Delete(model.ID);
                }

                setting.istransfer = this.cb_istransfer.Checked ? 1 : 0;

                setting.RiskWarning        = (byte)(this.ckb_rw_bank.Checked ? 1 : 0);
                setting.AlipayRiskWarning  = (byte)(this.ckb_rw_alipay.Checked ? 1 : 0);
                setting.AliCodeRiskWarning = (byte)(this.ckb_rw_alicode.Checked ? 1 : 0);
                setting.WxPayRiskWarning   = (byte)(this.ckb_rw_wxpay.Checked ? 1 : 0);

                this.setbll.Insert(_setting);
            }
        }