public static UserRole AddUserRole(UserRole userRole) { string sql = "INSERT UserRoles (Name)" + "VALUES (@Name)"; sql += " ; SELECT @@IDENTITY"; try { SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Name", userRole.Name) }; int newId = DBHelper.GetScalar(sql, para); return GetUserRoleById(newId); } catch (Exception e) { Console.WriteLine(e.Message); return null; } }
public static UserRole GetUserRoleById(int id) { string sql = "SELECT * FROM UserRoles WHERE Id = @Id"; try { SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@Id", id)); if (reader.Read()) { UserRole userRole = new UserRole(); userRole.Id = (int)reader["Id"]; userRole.Name = (string)reader["Name"]; reader.Close(); return userRole; } else { reader.Close(); return null; } } catch (Exception e) { Console.WriteLine(e.Message); return null; } }
public static void DeleteUserRole(UserRole userRole) { DeleteUserRoleById( userRole.Id ); }
private static IList<UserRole> GetUserRolesBySql( string sql, params SqlParameter[] values ) { List<UserRole> list = new List<UserRole>(); try { DataTable table = DBHelper.GetDataSet( sql, values ); foreach (DataRow row in table.Rows) { UserRole userRole = new UserRole(); userRole.Id = (int)row["Id"]; userRole.Name = (string)row["Name"]; list.Add(userRole); } return list; } catch (Exception e) { Console.WriteLine(e.Message); return null; } }
public static void ModifyUserRole(UserRole userRole) { string sql = "UPDATE UserRoles " + "SET " + "Name = @Name " + "WHERE Id = @Id"; try { SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Id", userRole.Id), new SqlParameter("@Name", userRole.Name) }; DBHelper.ExecuteCommand(sql, para); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }
public static void ModifyUserRole(UserRole userRole) { UserRoleService.ModifyUserRole(userRole); }
public static void DeleteUserRole(UserRole userRole) { UserRoleService.DeleteUserRole(userRole); }
public static UserRole AddUserRole(UserRole userRole) { return UserRoleService.AddUserRole(userRole); }