This commit is contained in:
2026-02-27 16:56:41 -08:00
parent d52ba6e59c
commit 6de30bd77e
17 changed files with 508 additions and 50 deletions
@@ -1,6 +1,7 @@
using System.Data;
using Dapper;
using MySql.Data.MySqlClient;
using WinStudentGoalTracker.Models;
namespace WinStudentGoalTracker.DataAccess;
@@ -8,11 +9,33 @@ public class StudentRepository
{
private IDbConnection Connection => new MySqlConnection(DatabaseManager.ConnectionString);
public async Task<IEnumerable<dbStudent>> GetAllAsync()
public async Task<IEnumerable<dbStudent>> GetMyStudentsAsync(Guid userId, Guid programId, string role)
{
return role switch
{
UserRoles.Teacher or UserRoles.ProgramAdmin =>
await GetStudentsByProgramAsync(programId),
UserRoles.Paraeducator =>
await GetAssignedStudentsAsync(userId, programId),
_ => Enumerable.Empty<dbStudent>()
};
}
public async Task<IEnumerable<dbStudent>> GetStudentsByProgramAsync(Guid programId)
{
using var db = Connection;
return await db.QueryAsync<dbStudent>(
"sp_Student_GetAll",
"sp_Student_GetByProgram",
new { p_id_program = programId.ToString() },
commandType: CommandType.StoredProcedure);
}
private async Task<IEnumerable<dbStudent>> GetAssignedStudentsAsync(Guid userId, Guid programId)
{
using var db = Connection;
return await db.QueryAsync<dbStudent>(
"sp_Student_GetByUserAndProgram",
new { p_id_user = userId.ToString(), p_id_program = programId.ToString() },
commandType: CommandType.StoredProcedure);
}
@@ -25,15 +48,16 @@ public class StudentRepository
commandType: CommandType.StoredProcedure);
}
public async Task<dbStudent?> InsertAsync(CreateStudentDto dto)
public async Task<dbStudent?> InsertAsync(CreateStudentDto dto, Guid newStudentGuid, Guid programId, Guid userId)
{
using var db = Connection;
return await db.QuerySingleOrDefaultAsync<dbStudent>(
"sp_Student_Insert",
new
{
p_id_student = dto.IdStudent.ToString(),
p_id_program = dto.IdProgram?.ToString(),
p_id_student = newStudentGuid.ToString(),
p_id_program = programId,
p_id_user = userId.ToString(),
p_identifier = dto.Identifier,
p_program_year = dto.ProgramYear,
p_enrollment_date = dto.EnrollmentDate,
@@ -50,7 +74,6 @@ public class StudentRepository
new
{
p_id_student = idStudent.ToString(),
p_id_program = dto.IdProgram?.ToString(),
p_identifier = dto.Identifier,
p_program_year = dto.ProgramYear,
p_enrollment_date = dto.EnrollmentDate,