Files
PaymentLogs/sql2/Repositories/StudentRepo.cs
T
2024-05-23 23:21:24 +03:00

48 lines
1.3 KiB
C#

using MySql.Data.MySqlClient;
using PaymentLogs.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PaymentLogs.Repositories
{
internal class StudentRepo : Repo<int, Student>
{
public override void Load()
{
DataBase db = new DataBase();
db.openConnection();
_data.Clear();
string sql = " SELECT * FROM students ";
MySqlCommand cmd = new MySqlCommand(sql, db.getConnection());
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Student student = new Student()
{
Id = reader.GetInt32("id"),
FCs = reader.GetString("fcs"),
dateOfBirth = DateTime.ParseExact(reader.GetString("date_of_birth"), "yyyy-MM-dd",null),
Address = reader.GetString("address"),
CourseId = reader.GetInt32("course_id"),
Paid = reader.GetInt32("paid")
};
_data[student.Id] = student;
}
db.closeConnection();
}
public override void Save()
{
throw new NotImplementedException();
}
}
}