Рабочее Fuel
This commit is contained in:
parent
597a48c846
commit
39d93173d3
@ -120,6 +120,7 @@
|
|||||||
numericUpDownAmount.DecimalPlaces = 2;
|
numericUpDownAmount.DecimalPlaces = 2;
|
||||||
numericUpDownAmount.Location = new Point(120, 89);
|
numericUpDownAmount.Location = new Point(120, 89);
|
||||||
numericUpDownAmount.Margin = new Padding(3, 4, 3, 4);
|
numericUpDownAmount.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
numericUpDownAmount.Maximum = new decimal(new int[] { 10000, 0, 0, 0 });
|
||||||
numericUpDownAmount.Minimum = new decimal(new int[] { 1, 0, 0, 131072 });
|
numericUpDownAmount.Minimum = new decimal(new int[] { 1, 0, 0, 131072 });
|
||||||
numericUpDownAmount.Name = "numericUpDownAmount";
|
numericUpDownAmount.Name = "numericUpDownAmount";
|
||||||
numericUpDownAmount.Size = new Size(160, 27);
|
numericUpDownAmount.Size = new Size(160, 27);
|
||||||
|
@ -1,28 +1,121 @@
|
|||||||
using FuelAndLubricants.Entities;
|
using Dapper;
|
||||||
|
using FuelAndLubricants.Entities;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
|
||||||
namespace FuelAndLubricants.Repositories.Implementations;
|
namespace FuelAndLubricants.Repositories.Implementations;
|
||||||
|
|
||||||
public class FuelRepository : IFuelRepository
|
public class FuelRepository : IFuelRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<FuelRepository> _logger;
|
||||||
|
|
||||||
|
public FuelRepository(IConnectionString connectionString, ILogger<FuelRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateFuel(Fuel_And_Lubricants fuel)
|
public void CreateFuel(Fuel_And_Lubricants fuel)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(fuel));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"INSERT INTO Fuel_And_Lubricants (Fuel_Type, Price_Per_Liter, Amount)
|
||||||
|
VALUES (@Fuel_Type, @Price_Per_Liter, @Amount)";
|
||||||
|
connection.Execute(queryInsert, fuel);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void DeleteFuel(int id)
|
public void DeleteFuel(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM Fuel_And_Lubricants
|
||||||
|
WHERE Fuel_ID=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Fuel_And_Lubricants ReadFuelByID(int id)
|
public Fuel_And_Lubricants ReadFuelByID(int id)
|
||||||
{
|
{
|
||||||
return Fuel_And_Lubricants.CreateEntity(0, 0, 0, 0);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Fuel_And_Lubricants
|
||||||
|
WHERE Fuel_ID=@id";
|
||||||
|
var fuel = connection.QueryFirst<Fuel_And_Lubricants>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(fuel));
|
||||||
|
return fuel;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Fuel_And_Lubricants> ReadFuels()
|
public IEnumerable<Fuel_And_Lubricants> ReadFuels()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Fuel_And_Lubricants";
|
||||||
|
var fuels = connection.Query<Fuel_And_Lubricants>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(fuels));
|
||||||
|
return fuels;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateFuel(Fuel_And_Lubricants fuel)
|
public void UpdateFuel(Fuel_And_Lubricants fuel)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(fuel));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE Fuel_And_Lubricants
|
||||||
|
SET
|
||||||
|
Fuel_Type=@Fuel_Type,
|
||||||
|
Price_Per_Liter=@Price_Per_Liter,
|
||||||
|
Amount=@Amount
|
||||||
|
WHERE Fuel_ID=@Fuel_ID";
|
||||||
|
connection.Execute(queryUpdate, fuel);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user