Exemple #1
0
        public async Task <BaseResult <DropDownList> > Add(UserEntity userEntity)
        {
            //判断数据库中有没有邮箱(user_email)和电话(user_phone),如果存在则不能添加,提示错误
            int count = await userRepository.CountAsync(c => c.user_email == userEntity.user_email || c.user_phone == userEntity.user_phone);

            if (count >= 1)
            {
                return(new BaseResult <DropDownList>(1003, null));
            }

            //同步添加三个数据库 User和UserInfo以及角色用户表--完善用户信息
            userEntity.user_pwd    = CommonUtil.Md5(userEntity.user_pwd);
            userEntity.user_name   = CommonUtil.AZReadRandom(6);
            userEntity.user_code   = CommonUtil.ReadRandom("#", 4, 9);
            userEntity.user_ip     = httpContextUtil.getRemoteIp();
            userEntity.source_type = (int)SourceStatus.front;
            userEntity.user_gender = (int)GenderStatus.mystery;

            UserInfoEntity userInfoEntity = new UserInfoEntity();

            userInfoEntity.user_id = userEntity.user_id;

            var userRole = await roleRepository.GetAsync(c => c.role_type == (int)RoleType.Front);

            if (userRole != null)
            {
                var isUserRoleTrue = await userRoleRepository.AddAsync(new UserRoleEntity()
                {
                    user_id = userEntity.user_id,
                    role_id = userRole.role_id
                }, false);
            }
            var isUserTrue = await userRepository.AddAsync(userEntity, false);

            var isUserInfoTrue = await userInfoRepository.AddAsync(userInfoEntity, false);

            if (unitOfWork.SaveCommit())
            {
                return(new BaseResult <DropDownList>(200, new DropDownList()
                {
                    name = userEntity.user_id,
                    value = userEntity.user_email
                }));
            }
            return(new BaseResult <DropDownList>(201, null));
        }