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 ServiceRepository : BaseRepository, IServiceRepository
|
|
{
|
|
public ServiceRepository(IOptions<DatabaseSettings> databaseSettings) : base(databaseSettings)
|
|
{
|
|
}
|
|
|
|
public IEnumerable<Service> GetAll()
|
|
{
|
|
string sql = "SELECT * FROM services";
|
|
List<Service> result = new();
|
|
|
|
try
|
|
{
|
|
OpenConnection();
|
|
using var mc = new MySqlCommand(sql, connection);
|
|
using var reader = mc.ExecuteReader();
|
|
while (reader.Read())
|
|
{
|
|
result.Add(new Service()
|
|
{
|
|
Id = reader.GetInt32("id"),
|
|
Title = reader.GetString("title"),
|
|
Description = reader.GetString("description")
|
|
});
|
|
}
|
|
CloseConnection();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
return result;
|
|
|
|
}
|
|
}
|
|
}
|