using MySql.Data.MySqlClient; using PaymentLogs.Domain; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PaymentLogs.Repositories { internal class CourseRepo : Repo { public override void Load() { DataBase db = new DataBase(); db.openConnection(); _data.Clear(); string sql = " SELECT * FROM courses "; MySqlCommand cmd = new MySqlCommand(sql, db.getConnection()); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Course course = new Course() { Id = reader.GetInt32("id"), Name = reader.GetString("name"), Type = reader.GetString("type"), Cost = reader.GetInt32("cost"), Duration = reader.GetInt32("duration"), StudentsCount = reader.GetInt32("students_count") }; _data[course.Id] = course; } db.closeConnection(); } public override void Save() { throw new NotImplementedException(); } public Course ByName(string name) { foreach (var course in _data.Values) { if (course.Name.ToLower().Equals(name.ToLower())) { return course; } } return _data.Values.FirstOrDefault(); } } }