public async Task<IActionResult> OnGetAsync() { UserName = HttpContext.Session.GetString(SessionKeyName1); UserEmail = HttpContext.Session.GetString(SessionKeyName2); Console.WriteLine("Current session: " + UserName); if (string.IsNullOrEmpty(UserName)) { Console.WriteLine("Session ended"); return RedirectToPage("/UserLoggedIn/SuccessLogIn"); } else { Console.WriteLine("Retrieving modules"); var connectionStringBuilder = new SqliteConnectionStringBuilder(); DatabaseConnect DBCon = new DatabaseConnect(); // your own class and method in DatabaseConnection folder string dbStringConnection = DBCon.DBStringConnection(); connectionStringBuilder.DataSource = dbStringConnection; var connection = new SqliteConnection(connectionStringBuilder.ConnectionString); connection.Open(); var selectCmd = connection.CreateCommand(); selectCmd.CommandText = @"SELECT * FROM Modules ORDER BY ModLevel"; var reader = selectCmd.ExecuteReader(); while (reader.Read()) { Modules mod = new Modules(); mod.ModCode = reader.GetString(1); mod.ModName = reader.GetString(2); mod.ModLevel = reader.GetInt32(3); mod.ModSemester = reader.GetInt32(4); ModRecords.Add(mod); IsSelect.Add(false); } connection.Close(); return Page(); } }
public IActionResult OnGet() { UserName = HttpContext.Session.GetString(SessionKeyName1); UserEmail = HttpContext.Session.GetString(SessionKeyName2); Console.WriteLine("Current session: " + UserName); if (string.IsNullOrEmpty(UserName)) { Console.WriteLine("Session ended"); return(RedirectToPage("/UserLoggedIn/SuccessLogIn")); } else { Console.WriteLine("Retrieving modules"); var connectionStringBuilder = new SqliteConnectionStringBuilder(); DatabaseConnect DBCon = new DatabaseConnect(); // your own class and method in DatabaseConnection folder string dbStringConnection = DBCon.DBStringConnection(); connectionStringBuilder.DataSource = dbStringConnection; var connection = new SqliteConnection(connectionStringBuilder.ConnectionString); connection.Open(); var selectCmd = connection.CreateCommand(); selectCmd.CommandText = @"SELECT ModCode FROM RegisteredModule WHERE StudenEmail=$email ORDER BY ModCode"; selectCmd.Parameters.AddWithValue("$email", UserEmail); var reader = selectCmd.ExecuteReader(); List <String> GetRegMod = new List <string>(); //to get module that registered by the student while (reader.Read()) { GetRegMod.Add(reader.GetString(0)); } for (int i = 0; i < GetRegMod.Count; i++) { var ModCode = GetRegMod[i]; var selectCmd2 = connection.CreateCommand(); selectCmd2.CommandText = @"SELECT ModName FROM Modules WHERE ModCode=$modCode ORDER BY ModCode"; selectCmd2.Parameters.AddWithValue("$modCode", ModCode); var reader2 = selectCmd2.ExecuteReader(); while (reader2.Read()) { Modules rec = new Modules(); rec.ModCode = GetRegMod[i]; rec.ModName = reader2.GetString(0); ModRecords.Add(rec); } IsSelect.Add(false); } return(Page()); } }