Правки
This commit is contained in:
parent
dcaac2153e
commit
2cde8b4735
@ -4,7 +4,7 @@ namespace ProjectGasStation.Repositories;
|
|||||||
|
|
||||||
public interface IShiftRepository
|
public interface IShiftRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Shift> ReadShifts(DateTime? dateFrom = null, DateTime? dateTo = null);
|
IEnumerable<Shift> ReadShifts();
|
||||||
Shift ReadShiftById(int id);
|
Shift ReadShiftById(int id);
|
||||||
void CreateShift(Shift shift);
|
void CreateShift(Shift shift);
|
||||||
void UpdateShift(Shift shift);
|
void UpdateShift(Shift shift);
|
||||||
|
@ -78,23 +78,14 @@ public class ShiftRepository : IShiftRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Shift> ReadShifts(DateTime? dateFrom = null, DateTime? dateTo = null)
|
public IEnumerable<Shift> ReadShifts()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var builder = new QueryBuilder();
|
|
||||||
if (dateFrom.HasValue)
|
|
||||||
{
|
|
||||||
builder.AddCondition("Date >= @dateFrom");
|
|
||||||
}
|
|
||||||
if (dateTo.HasValue)
|
|
||||||
{
|
|
||||||
builder.AddCondition("Date <= @dateTo");
|
|
||||||
}
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = $"SELECT * FROM Shift {builder.Build()}";
|
var querySelect = "SELECT * FROM Shift";
|
||||||
var shifts = connection.Query<Shift>(querySelect, new { dateFrom, dateTo });
|
var shifts = connection.Query<Shift>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(shifts));
|
JsonConvert.SerializeObject(shifts));
|
||||||
return shifts;
|
return shifts;
|
||||||
|
Loading…
Reference in New Issue
Block a user