예제 #1
0
        /// <summary>
        /// 保存用户角色关系
        /// </summary>
        /// <param name="accountId">用户Id</param>
        /// <param name="roleIds">角色Id集合</param>
        /// <param name="operational">操作信息</param>
        /// <returns>结果</returns>
        public static Result SavePermissionRole(Guid accountId, List <Guid> roleIds, Operational operational)
        {
            Result result = new Result();

            try
            {
                using (IPowerUnitOfWork unit = DbContext.CreateIPowerUnitOfWork())
                {
                    IRoleUserRelationshipRepository roleUserRelationshipRepository = DbContext.CreateIRoleUserRelationshipRepository(unit);
                    roleUserRelationshipRepository.RemoveByAccountId(accountId);
                    var content = PermissionBuilder.ToMRoleUserRelationship(accountId, roleIds);
                    roleUserRelationshipRepository.Add(content);
                    unit.Complete();
                }

                result.IsSucceed = true;
                result.Message   = "保存成功";
            }
            catch (Exception ex)
            {
                result.IsSucceed = false;
                result.Message   = Const.ErrorMessage;
                LogService.WriteLog(ex, "保存用户角色关系");
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 保存权限菜单
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <param name="menuIds">菜单Id集合</param>
        /// <param name="operational">操作信息</param>
        /// <returns>结果</returns>
        public static Result SavePermissionMenu(Guid roleId, List <Guid> menuIds, Operational operational)
        {
            Result result = new Result();

            try
            {
                PermissionValidate.ValidateMenuIds(menuIds);
                using (IPowerUnitOfWork unit = DbContext.CreateIPowerUnitOfWork())
                {
                    IRolePermissionsRepository rolePermissionsRepository = DbContext.CreateIRolePermissionsRepository(unit);
                    rolePermissionsRepository.RemoveByRoleId(roleId);
                    var content = PermissionBuilder.ToMRolePermissions(roleId, menuIds);
                    rolePermissionsRepository.Add(content);
                    unit.Complete();
                }

                result.IsSucceed = true;
                result.Message   = "保存成功";
            }
            catch (CustomException ex)
            {
                result.IsSucceed = false;
                result.Message   = ex.Message;
            }
            catch (Exception ex)
            {
                result.IsSucceed = false;
                result.Message   = Const.ErrorMessage;
                LogService.WriteLog(ex, "保存权限菜单");
            }
            return(result);
        }