public override bool RoleExists(string roleName) { /*bool exists = false; System.Data.SqlClient.SqlConnection objConn = new System.Data.SqlClient.SqlConnection(connStr); System.Data.SqlClient.SqlCommand objComm = new System.Data.SqlClient.SqlCommand("SELECT COUNT(*) FROM ULOGA WHERE NAZIV = @NAZIV", objConn); objComm.Parameters.Add("@NAZIV", SqlDbType.NVarChar, 256).Value = roleName; objConn.Open(); int numRecs = (int)objComm.ExecuteScalar(); if (numRecs > 0) { exists = true; } objConn.Close(); return exists;*/ UserRoleBL userRoleBL = new UserRoleBL(); return userRoleBL.UserRoleExists(roleName); }
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { foreach (string rolename in roleNames) { if (!RoleExists(rolename)) { throw new System.Configuration.Provider.ProviderException("Naziv uloge nije pronadjen."); } } foreach (string username in usernames) { foreach (string rolename in roleNames) { if (!IsUserInRole(username, rolename)) { throw new System.Configuration.Provider.ProviderException("Korisnik ne pripada ulozi."); } } } UserRoleBL userRoleBL = new UserRoleBL(); userRoleBL.RemoveUserFromUserRole(usernames[0], roleNames[0]); /*System.Data.SqlClient.SqlConnection objConn = new System.Data.SqlClient.SqlConnection(connStr); System.Data.SqlClient.SqlCommand objComm = new System.Data.SqlClient.SqlCommand("DELETE FROM KORISNIKULOGE WHERE ID_KORISNIK = @ID_KORISNIK AND ID_ULOGA = @ID_ULOGA", objConn); System.Data.SqlClient.SqlParameter userParam = objComm.Parameters.Add("@ID_KORISNIK", SqlDbType.Int); System.Data.SqlClient.SqlParameter roleParam = objComm.Parameters.Add("@ID_ULOGA", SqlDbType.Int); System.Data.SqlClient.SqlTransaction tran = null; try { objConn.Open(); tran = objConn.BeginTransaction(); objComm.Transaction = tran; foreach (string username in usernames) { foreach (string rolename in roleNames) { userParam.Value = GetUserID(username); roleParam.Value = GetRoleID(rolename); objComm.ExecuteNonQuery(); } } tran.Commit(); } catch (System.Data.SqlClient.SqlException) { tran.Rollback(); } finally { objConn.Close(); }*/ }
public override bool IsUserInRole(string username, string roleName) { UserRoleBL userRoleBL = new UserRoleBL(); return userRoleBL.IsUserInRole(username, roleName); /*bool userIsInRole = false; System.Data.SqlClient.SqlConnection objConn = new System.Data.SqlClient.SqlConnection(connStr); System.Data.SqlClient.SqlCommand objComm = new System.Data.SqlClient.SqlCommand("SELECT COUNT(*) FROM KORISNIKULOGE WHERE ID_KORISNIK = @ID_KORISNIK AND ID_ULOGA = @ID_ULOGA", objConn); objComm.Parameters.Add("@ID_ULOGA", SqlDbType.Int).Value = GetRoleID(roleName); objComm.Parameters.Add("@ID_KORISNIK", SqlDbType.Int).Value = GetUserID(username); objConn.Open(); int numRecs = (int)objComm.ExecuteScalar(); if (numRecs > 0) { userIsInRole = true; } objConn.Close(); return userIsInRole;*/ }
public override string[] GetRolesForUser(string username) { UserRoleBL userRoleBL=new UserRoleBL(); string[] userRoles = userRoleBL.GetUserRolesForUsername(username); string roles=string.Empty; /*foreach (UserRole userRole in userRoles) roles += userRole.Name + ",";*/ return userRoles; //return roles.Substring(roles.Length - 1, 1).Split(','); /*string tmpRoleNames = ""; System.Data.SqlClient.SqlConnection objConn = new System.Data.SqlClient.SqlConnection(connStr); System.Data.SqlClient.SqlCommand objComm = new System.Data.SqlClient.SqlCommand("SELECT ID_ULOGA FROM KORISNIKULOGE WHERE ID_KORISNIK = @ID_KORISNIK", objConn); int id=GetUserID(username); objComm.Parameters.Add("@ID_KORISNIK", SqlDbType.Int).Value = id; System.Data.SqlClient.SqlDataReader reader = null; try { objConn.Open(); reader = objComm.ExecuteReader(); while (reader.Read()) { tmpRoleNames += GetRoleName(reader.GetInt32(0)) + ","; } } finally { if (reader != null) reader.Close(); objConn.Close(); } if (tmpRoleNames.Length > 0) { tmpRoleNames = tmpRoleNames.Substring(0, tmpRoleNames.Length - 1); return tmpRoleNames.Split(','); } return new string[0];*/ }
public override string[] GetAllRoles() { UserRoleBL userRoleBL = new UserRoleBL(); System.Collections.Generic.List<UserRole> userRoles = userRoleBL.GetAllUserRoles(false); string roles=string.Empty; foreach (UserRole userRole in userRoles) roles += userRole.Name + ","; return roles.Substring(roles.Length - 1, 1).Split(','); /*string tmpRoleNames = ""; System.Data.SqlClient.SqlConnection objConn = new System.Data.SqlClient.SqlConnection(connStr); System.Data.SqlClient.SqlCommand objComm = new System.Data.SqlClient.SqlCommand("SELECT NAZIV FROM ULOGA", objConn); System.Data.SqlClient.SqlDataReader reader = null; try { objConn.Open(); reader = objComm.ExecuteReader(); while (reader.Read()) { tmpRoleNames += reader.GetString(0) + ","; } } finally { if (reader != null) reader.Close(); objConn.Close(); } if (tmpRoleNames.Length > 0) { tmpRoleNames = tmpRoleNames.Substring(0, tmpRoleNames.Length - 1); return tmpRoleNames.Split(','); } return new string[0];*/ }
public override void CreateRole(string roleName) { if (roleName.IndexOf(',') > 0) { throw new ArgumentException("Naziv uloge ne moze da sadrzi podvlake."); } if (RoleExists(roleName)) { throw new System.Configuration.Provider.ProviderException("Naziv uloge vec postoji."); } UserRoleBL userRoleBL = new UserRoleBL(); UserRole userRole = new UserRole(); userRole.Name = roleName; //userRole._InsertDate = DateTime.Now; //userRole._UpdateDate = DateTime.Now; //userRole._UserIDInsert = int.Parse(Membership.GetUser().ProviderUserKey.ToString()); //userRole._UserIDUpdate = int.Parse(Membership.GetUser().ProviderUserKey.ToString()); userRoleBL.Save(userRole); /*System.Data.SqlClient.SqlConnection objConn = new System.Data.SqlClient.SqlConnection(connStr); System.Data.SqlClient.SqlCommand objComm = new System.Data.SqlClient.SqlCommand("INSERT INTO ULOGA (NAZIV) VALUES(@NAZIV)", objConn); objComm.Parameters.Add("@NAZIV", SqlDbType.NVarChar, 256).Value = roleName; objConn.Open(); objComm.ExecuteNonQuery(); objConn.Close();*/ }