private bool PopulatedRole(RoleInfo role) { try { InstConn(); SqlCommand roleCheck = Connection.CreateCommand(); roleCheck.CommandText = "SELECT * FROM " + role.Table + " where " + role.IdType + " = @Id"; roleCheck.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value = role.Id; // Execute scalar returns null if role is empty // Connection.Open(); bool rolePopd = !(roleCheck.ExecuteScalar() == null); ConnClose(); return rolePopd; } catch { return false; } }
public bool IsUserInRole(int uId, RoleInfo role) { try { InstConn(); SqlCommand comm = Connection.CreateCommand(); comm.CommandText = "SELECT UserId FROM " + role.Table + " WHERE " + role.IdType + " = @RoleId AND UserId = @UserId"; comm.Parameters.Add("@RoleId", System.Data.SqlDbType.Int).Value = role.Id; comm.Parameters.Add("@UserId", System.Data.SqlDbType.Int).Value = uId; // Connection.Open(); if (comm.ExecuteScalar() == null) { ConnClose(); return false; } ConnClose(); return true; } catch { ConnClose(); return false; } }