Example #1
0
        public override void Create(RoleDataModel role)
        {
            if (!SecurityManager.SesionStarted())
            {
                throw new Exception("Session not started");
            }
            role.CreatedBy = SecurityManager.GetLoggedUser().ID;
            role.DateCreated = DateTime.Now;

            base.Create(role);
        }
Example #2
0
        public static RoleDataModel Get(int id)
        {
            RoleDataModel role = null;

            MySqlConnection connection = new MySqlConnection(ConfigurationManager.AppSettings[BusinessUtilies.Const.Database.AppSetting]);
            MySqlDataAdapter adapter = new MySqlDataAdapter("Core_GetRoleByID", connection);
            MySqlParameter paramID = new MySqlParameter("pId", id);
            paramID.Direction = ParameterDirection.Input;
            adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
            adapter.SelectCommand.Parameters.Add(paramID);

            DataTable results = new DataTable();

            adapter.Fill(results);

            if (results.Rows.Count > 0)
            {
                DataRow item = results.Rows[0];
                role = new RoleDataModel();

                if (item["ID"].GetType() != typeof(DBNull))
                {
                    role.ID = Convert.ToInt32(item["ID"]);
                }
                if (item["Name"].GetType() != typeof(DBNull))
                {
                    role.Name = Convert.ToString(item["Name"]);
                }
                if (item["DateCreated"].GetType() != typeof(DBNull))
                {
                    role.DateCreated = Convert.ToDateTime(item["DateCreated"]);
                }
                if (item["CreatedBy"].GetType() != typeof(DBNull))
                {
                    role.CreatedBy = Convert.ToInt32(item["CreatedBy"]);
                }
            }

            return role;
        }
Example #3
0
        public static void Create(RoleDataModel role)
        {
            MySqlConnection connection = new MySqlConnection(ConfigurationManager.AppSettings[BusinessUtilies.Const.Database.AppSetting]);
            MySqlDataAdapter adapter = new MySqlDataAdapter("Core_CreateRole", connection);
            adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

            MySqlParameter paramID = new MySqlParameter("pID", role.ID);
            paramID.Direction = ParameterDirection.Input;
            adapter.SelectCommand.Parameters.Add(paramID);
            MySqlParameter paramName = new MySqlParameter("pName", role.Name);
            paramName.Direction = ParameterDirection.Input;
            adapter.SelectCommand.Parameters.Add(paramName);
            MySqlParameter paramDateCreated = new MySqlParameter("pDateCreated", role.DateCreated);
            paramDateCreated.Direction = ParameterDirection.Input;
            adapter.SelectCommand.Parameters.Add(paramDateCreated);
            MySqlParameter paramCreatedBy = new MySqlParameter("pCreatedBy", role.CreatedBy);
            paramCreatedBy.Direction = ParameterDirection.Input;
            adapter.SelectCommand.Parameters.Add(paramCreatedBy);

            DataTable results = new DataTable();
            adapter.Fill(results);
        }
Example #4
0
        public static List<RoleDataModel> GetAll()
        {
            List<RoleDataModel> roles = new List<RoleDataModel>();

            MySqlConnection connection = new MySqlConnection(ConfigurationManager.AppSettings[BusinessUtilies.Const.Database.AppSetting]);
            MySqlDataAdapter adapter = new MySqlDataAdapter("Core_GetRoles", connection);
            DataTable results = new DataTable();

            adapter.Fill(results);

            foreach (DataRow item in results.Rows)
            {
                RoleDataModel role = new RoleDataModel();

                if (item["ID"].GetType() != typeof(DBNull))
                {
                    role.ID = Convert.ToInt32(item["ID"]);
                }
                if (item["Name"].GetType() != typeof(DBNull))
                {
                    role.Name = Convert.ToString(item["Name"]);
                }
                if (item["DateCreated"].GetType() != typeof(DBNull))
                {
                    role.DateCreated = Convert.ToDateTime(item["DateCreated"]);
                }
                if (item["CreatedBy"].GetType() != typeof(DBNull))
                {
                    role.CreatedBy = Convert.ToInt32(item["CreatedBy"]);
                }

                roles.Add(role);
            }

            return roles;
        }