Exemplo n.º 1
0
        private GrantBE Grants_Populate(IDataReader dr, GrantType grantType)
        {
            GrantBE grant = new GrantBE();

            grant.Id     = dr.Read <uint>("grantid");
            grant.PageId = dr.Read <uint>("pageid");
            if (grantType == GrantType.USER)
            {
                grant.UserId = dr.Read <uint>("userid");
            }
            else if (grantType == GrantType.GROUP)
            {
                grant.GroupId = dr.Read <uint>("groupid");
            }
            grant.ExpirationDate       = dr.Read <DateTime>("grant_expire_date", DateTime.MaxValue);
            grant.TimeStamp            = dr.Read <DateTime>("last_edit");
            grant.CreatorUserId        = dr.Read <uint>("grant_creator_userid");
            grant.Role                 = new RoleBE();
            grant.RoleId               = grant.Role.ID = dr.Read <uint>("role_id");
            grant.Role.Name            = dr.Read <string>("role_name", string.Empty);
            grant.Role.PermissionFlags = dr.Read <ulong>("role_perm_flags");
            grant.Role.TimeStamp       = dr.Read <DateTime>("role_last_edit");
            grant.Role.CreatorUserId   = dr.Read <uint>("role_creator_userid");
            grant.Role.Type            = RoleType.ROLE;
            grant.Type                 = grantType;
            return(grant);
        }
Exemplo n.º 2
0
        public uint Grants_Insert(GrantBE grant)
        {
            DataCommand cmd = null;

            // create the insertion command
            string query = string.Empty;

            if (grant.Type == GrantType.USER)
            {
                query = @" /* Grants_Insert (user) */
insert into user_grants (page_id, user_id, role_id, creator_user_id, expire_date)
values (?PAGEID, ?USERID, ?ROLEID, ?CREATORID, ?EXPIREDATE);
select LAST_INSERT_ID();";
                cmd   = Catalog.NewQuery(query)
                        .With("userid", grant.UserId);
            }
            else if (grant.Type == GrantType.GROUP)
            {
                query = @" /* Grants_Insert (group) */
insert into group_grants (page_id, group_id, role_id, creator_user_id, expire_date)
values (?PAGEID, ?GROUPID, ?ROLEID, ?CREATORID, ?EXPIREDATE);
select LAST_INSERT_ID();";
                cmd   = Catalog.NewQuery(query)
                        .With("groupid", grant.GroupId);
            }
            if (grant.ExpirationDate == DateTime.MaxValue)
            {
                cmd.With("expiredate", DBNull.Value);
            }
            else
            {
                cmd.With("expiredate", grant.ExpirationDate);
            }
            return(cmd.With("pageid", grant.PageId)
                   .With("roleid", grant.RoleId)
                   .With("creatorid", grant.CreatorUserId)
                   .ReadAsUInt() ?? 0);
        }