コード例 #1
0
ファイル: Permission.cs プロジェクト: XtremeKevinChow/rdroad
        /// <summary>
        ///  Map a DataRow to a Permission Entity.
        /// </summary>
        /// <returns></returns>
        public static Permission Row2Entity(System.Data.DataRow row)
        {
            if(row == null) return null;

            Permission entity = new Permission();

            if(!row.IsNull("PERM_ID"))
                    entity._permissionId= (int)(row["PERM_ID"]);
            if(!row.IsNull("OPT_ID"))
                    entity._operationId= (int)(row["OPT_ID"]);
            if(!row.IsNull("PERM_TYPE"))
                    entity._type= (PermissionType)Enum.Parse(typeof(PermissionType),(row["PERM_TYPE"]).ToString());
            if(!row.IsNull("USR_ID"))
                    entity._userId= (int)(row["USR_ID"]);
            if(!row.IsNull("UGP_ID"))
                    entity._groupId= (int)(row["UGP_ID"]);
            if(!row.IsNull("PERM_ALLOW"))
                    entity._isAllow= (bool)(row["PERM_ALLOW"]);
            if(!row.IsNull("CREATE_TIME"))
                    entity._createTime= (DateTime)(row["CREATE_TIME"]);
            if(!row.IsNull("CREATE_BY"))
                    entity._createBy= (int)(row["CREATE_BY"]);

               return entity;
        }
コード例 #2
0
 public bool AssignPermissions(PermissionType type, int[] priviledgerIds, int[] operationIds)
 {
     if (priviledgerIds == null || priviledgerIds.Length == 0)
     {
         throw new ArgumentNullException("privilegerIds");
     }
     if (operationIds == null || operationIds.Length == 0)
     {
         throw new ArgumentNullException("operationIds");
     }
     bool flag = true;
     foreach (int privildegerId in priviledgerIds)
     {
         foreach (int opId in operationIds)
         {
             if (!ExistsPermission(type, privildegerId, opId))
             {
                 Permission prm = new Permission();
                 if (type == PermissionType.OnUserGroup)
                 {
                     prm.GroupId = privildegerId;
                 }
                 else if (type == PermissionType.OnUser)
                 {
                     prm.UserId = privildegerId;
                 }
                 prm.OperationId = opId;
                 prm.IsAllow = true;
                 prm.Type = type;
                 prm.CreateBy = SecuritySession.CurrentUser.UserId;
                 prm.CreateTime = DateTime.Now;
                 if(!prm.Create(_session))
                     flag = false;
             }
         }
     }
     return flag;
 }