using Microsoft.Extensions.Options; using MySqlConnector; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AutoService.Models { public class WorkRepository : BaseRepository, IWorkRepository { public WorkRepository(IOptions databaseSettings) : base(databaseSettings) { } public IEnumerable GetByServiceId(int serviceId) { string sql = "SELECT id, work_name, price FROM works WHERE service_id=@SID"; List result = new(); try { OpenConnection(); using var mc = new MySqlCommand(sql, connection); mc.Parameters.AddWithValue("@SID", serviceId); using var reader = mc.ExecuteReader(); while (reader.Read()) { result.Add(new Work() { Id = reader.GetInt32("id"), Title = reader.GetString("work_name"), Price = reader.GetInt32("price") }); } CloseConnection(); }catch(Exception e) { Console.WriteLine(e); } return result; } } }