예제 #1
1
 /// <summary>
 /// 添加角色
 /// </summary>
 /// <param name="Options">添加参数</param>
 /// <param name="ReceiveMessage">回调消息</param>
 public void AddRole(BsonDocument Options, BsonDocument ReceiveMessage)
 {
     String RoleName = Options.GetValue("RoleName").AsString;
     UserRole ur = new UserRole();
     ur.UserRoleName = RoleName;
     ur.PUserRole = new ObjectId(Options.GetValue("PUserRole").AsString);
     ur.UserRolePowers = BsonHelper.StrinIdToObjectId(Options.GetValue("RolePowers").AsBsonArray);
     if (urs.ExsitRole(RoleName))
     {
         Boolean IsSuccess = urs.AddRole(ur);
         if (IsSuccess)
         {
             ReceiveMessage.Add("StateCode", 0);
             ReceiveMessage.Add("ReData", IsSuccess);
             CallBack();
         }
         else
         {
             ReceiveMessage.Add("StateCode", -2);
             ReceiveMessage.Add("ReData", "添加失败");
             CallBack();
         }
     }
     else
     {
         ReceiveMessage.Add("StateCode", -1);
         ReceiveMessage.Add("ReData", "角色名已存在!");
         CallBack();
     }
 }
예제 #2
0
 /// <summary>
 /// 查询角色信息
 /// </summary>
 /// <param name="RoleName">角色名</param>
 /// <returns>返回该角色</returns>
 public UserRole FindOne(String RoleName)
 {
     UserRole ur = null;
     BsonDocument RoleDoc = dh.FindOne("userroles", new BsonDocument { { "UserRoleName", RoleName } });
     if (RoleDoc != null)
     {
         ur = new UserRole(RoleDoc);
     }
     return ur;
 }
예제 #3
0
 /// <summary>
 /// 查询角色信息
 /// </summary>
 /// <param name="RoleId">角色Id</param>
 /// <returns>返回该角色</returns>
 public UserRole FindOne(ObjectId RoleId)
 {
     UserRole ur = null;
     BsonDocument RoleDoc = dh.FindOne("userroles", new BsonDocument { { "_id", RoleId } });
     if (RoleDoc != null)
     {
         ur = new UserRole(RoleDoc);
     }
     return ur;
 }
예제 #4
0
 /// <summary>
 /// 获取角色下所有角色
 /// </summary>
 /// <param name="RoleId">角色Id</param>
 /// <returns>返回所有角色集合</returns>
 public BsonArray GetAllChildren(ObjectId RoleId)
 {
     BsonArray RoleList = new BsonArray();
     List<BsonDocument> RoleDoc = dh.GetAllData("userroles", new BsonDocument { { "PUserRole", RoleId } });
     foreach (BsonDocument Role in RoleDoc)
     {
         UserRole ur = new UserRole(Role);
         ur.UserRolePowers = ups.GetAll(ur.UserRolePowers);
         RoleList.AddRange(GetAllChildren(ur.Id));
         RoleList.Add(ur.ToBsonDocument());
     }
     return RoleList;
 }
예제 #5
0
 /// <summary>
 /// 添加角色
 /// </summary>
 /// <param name="ur">角色</param>
 /// <returns>是否添加成功</returns>
 public Boolean AddRole(UserRole ur)
 {
     return dh.InsertData("userroles", ur.ToBsonDocument()) != null;
 }