47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
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> databaseSettings) : base(databaseSettings)
|
|
{
|
|
}
|
|
|
|
public IEnumerable<Work> GetByServiceId(int serviceId)
|
|
{
|
|
string sql = "SELECT id, work_name, price FROM works WHERE service_id=@SID";
|
|
List<Work> 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;
|
|
}
|
|
}
|
|
}
|