Example #1
0
        public void RegisterUser(SystemUser user, string[] roleIds)
        {
            if (roleIds.Length == 0)
            {
                throw new AuthException("必须指定角色");
            }

            DB.Begin();

            var            lastKey = DB.CreateQuery <C_Auth_KeyRule>().Where(p => p.RuleKey == "MAXKEY").FirstOrDefault();
            IList <string> skipList;

            user.UserId = BeautyNumberHelper.GetNextCommonNumber(lastKey.RuleValue, out skipList);

            var roleList = GetRoleListByIds(roleIds);

            if (roleList.Count != roleIds.Length)
            {
                throw new AuthException("指定的角色可能不存在 - " + string.Join(",", roleIds));
            }
            user.RoleList = roleList;
            //userManager.AddSystemUser(user);
            UpdateLastUserKey(user.UserId, skipList.Count);
            if (skipList.Count > 0)
            {
                AddSkipBeautyKey(skipList.ToArray(), lastKey.RuleValue, user.UserId);
            }

            DB.Commit();
        }
        public void RegisterUser(SystemUser user, string[] roleIds)
        {
            if (roleIds.Length == 0)
            {
                throw new AuthException("必须指定角色");
            }
            using (var biz = new GameBizAuthBusinessManagement())
            {
                biz.BeginTran();
                using (var userManager = new UserManager())
                {
                    var            lastKey = userManager.GetLastUserKey();
                    IList <string> skipList;
                    user.UserId = BeautyNumberHelper.GetNextCommonNumber(lastKey, out skipList);

                    var roleList = userManager.GetRoleListByIds(roleIds);
                    if (roleList.Count != roleIds.Length)
                    {
                        throw new AuthException("指定的角色可能不存在 - " + string.Join(",", roleIds));
                    }
                    user.RoleList = roleList;
                    userManager.AddSystemUser(user);
                    userManager.UpdateLastUserKey(user.UserId, skipList.Count);
                    if (skipList.Count > 0)
                    {
                        userManager.AddSkipBeautyKey(skipList.ToArray(), lastKey, user.UserId);
                    }
                }
                biz.CommitTran();
            }
        }
Example #3
0
        public void RegisterUser(SystemUser user, string[] roleIds)
        {
            if (roleIds.Length == 0)
            {
                throw new LogicException("必须指定角色");
            }

            DB.Begin();
            try
            {
                var            lastKey = DB.CreateQuery <C_Auth_KeyRule>().Where(p => p.RuleKey == "MAXKEY").FirstOrDefault();
                IList <string> skipList;
                user.UserId = BeautyNumberHelper.GetNextCommonNumber(lastKey.RuleValue, out skipList);

                var roleList = GetRoleListByIds(roleIds);
                if (roleList == null)
                {
                    throw new LogicException("指定的角色可能不存在 - " + string.Join(",", roleIds));
                }
                //user.RoleList = roleList;
                var Auth_UserRole = new C_Auth_UserRole
                {
                    UserId = user.UserId,
                    RoleId = roleList
                };

                DB.GetDal <C_Auth_UserRole>().Add(Auth_UserRole);
                //userManager.AddSystemUser(user);
                UpdateLastUserKey(user.UserId, skipList.Count);
                if (skipList.Count > 0)
                {
                    AddSkipBeautyKey(skipList.ToArray(), lastKey.RuleValue, user.UserId);
                }

                DB.Commit();
            }
            catch (Exception ex)
            {
                DB.Rollback();
                throw ex;
            }
        }