Ejemplo n.º 1
0
        /// <summary>
        /// Add a role with a specific permission, or add permission to an existing role.
        /// </summary>
        /// <param name="rolename">The name of the role.</param>
        /// <param name="resource">The resource.</param>
        /// <param name="operation">The type of operation.</param>
        /// <param name="allow">Permit (true) or deny (false).</param>
        public void AddRolePermission(string rolename, string resource, string operation, bool allow)
        {
            if (String.IsNullOrEmpty(rolename))
            {
                throw new ArgumentNullException(nameof(rolename));
            }
            if (String.IsNullOrEmpty(resource))
            {
                throw new ArgumentNullException(nameof(resource));
            }
            if (String.IsNullOrEmpty(operation))
            {
                throw new ArgumentNullException(nameof(operation));
            }
            RolePermission r = new RolePermission(rolename, resource, operation, allow);

            _ORM.Insert <RolePermission>(r);
        }
Ejemplo n.º 2
0
        public static RolePermission FromDataRow(DataRow row)
        {
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }
            RolePermission r = new RolePermission();

            r.RoleName  = row["rolename"].ToString();
            r.Resource  = row["resource"].ToString();
            r.Operation = row["operation"].ToString();

            if (Convert.ToInt32(row["allow"]) > 0)
            {
                r.Allow = true;
            }
            else
            {
                r.Allow = false;
            }

            return(r);
        }
Ejemplo n.º 3
0
        public List <RolePermission> GetRolePermissions(string role)
        {
            if (String.IsNullOrEmpty(role))
            {
                throw new ArgumentNullException(nameof(role));
            }

            string    query  = "SELECT * FROM role_perm WHERE rolename = '" + DatabaseClient.SanitizeString(role) + "'";
            DataTable result = Db.Query(query);

            List <RolePermission> ret = new List <RolePermission>();

            if (result != null && result.Rows.Count > 0)
            {
                foreach (DataRow curr in result.Rows)
                {
                    RolePermission r = RolePermission.FromDataRow(curr);
                    ret.Add(r);
                }
            }

            ret = ret.Distinct().ToList();
            return(ret);
        }