• Decrease Text SizeIncrease Text Size

RoleInfo Class

Posted Date: 5/3/2023
    Printer Friendly Version   Email A Friend   Add This   Increase Text Size   Decrease Text Size
this class provides you with information about the role.


using Centralpoint.Web;
using System;
using System.Data.SqlClient;

namespace Centralpoint.WebSite
{
    public class RoleInfo
    {
        private Guid _roleId;
        private string _systemName, _name, _description = String.Empty, _integrationId = String.Empty;
        private bool _isDataRole, _isSystem;
        private DateTime _createDate, _modifyDate = DateTime.MinValue;

        public RoleInfo(string systemName)
        {
            if (String.IsNullOrEmpty(systemName)) throw new Exception("You must provide a system name.");

            using (SqlConnection connection = new SqlConnection(Management.Application.SelectConnectionString))
            {
                SqlCommand command = new SqlCommand(String.Format("SELECT TOP 1 RoleId, SystemName, [Name], [Description], IntegrationId, IsDataRole, IsSystem, CreateDate, ModifyDate FROM cpsys_Roles WHERE SystemName = N'{0}'", systemName.SqlEncode()), connection);
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        _roleId = reader.GetGuid(0);
                        _systemName = reader.GetString(1);
                        _name = reader.GetString(2);
                        if (!reader.IsDBNull(3)) _description = reader.GetString(3);
                        if (!reader.IsDBNull(4)) _integrationId = reader.GetString(4);
                        _isDataRole = reader.GetBoolean(5);
                        _isSystem = reader.GetBoolean(6);
                        _createDate = reader.GetDateTime(7);
                        if (!reader.IsDBNull(8)) _modifyDate = reader.GetDateTime(8);
                    }
                    else
                        throw new Exception(String.Format("The {0} role could not be found.", systemName));
                }
            }
        }

        public Guid RoleId
        {
            get { return _roleId; }
        }

        public string SystemName
        {
            get { return _systemName; }
        }

        public string Name
        {
            get { return _name; }
        }

        public string Description
        {
            get { return _description; }
        }

        public string IntegrationId
        {
            get { return _integrationId; }
        }

        public bool IsDataRole
        {
            get { return _isDataRole; }
        }

        public bool IsSystem
        {
            get { return _isSystem; }
        }

        public DateTime CreateDate
        {
            get { return _createDate; }
        }

        public DateTime ModifyDate
        {
            get { return _modifyDate; }
        }
    }
}




Keywords: Roles



Related Taxonomy

Comments:

Be the first to leave a comment.
Please Login to post comments.