diff --git a/GasStation/Entities/Product.cs b/GasStation/Entities/Product.cs
index 934c577..8768a49 100644
--- a/GasStation/Entities/Product.cs
+++ b/GasStation/Entities/Product.cs
@@ -6,16 +6,16 @@ public class Product
{
public int Id { get; private set; }
- public int Cost { get; private set; }
+ public int ProductCost { get; private set; }
public ProductType ProductType { get; private set; }
- public static Product CreateProduct(int id, int cost, ProductType productType)
+ public static Product CreateProduct(int id, int productCost, ProductType productType)
{
return new Product
{
Id = id,
- Cost = cost,
+ ProductCost = productCost,
ProductType = productType
};
}
diff --git a/GasStation/Entities/Supplier.cs b/GasStation/Entities/Supplier.cs
index 5e4916f..9098421 100644
--- a/GasStation/Entities/Supplier.cs
+++ b/GasStation/Entities/Supplier.cs
@@ -4,14 +4,14 @@ public class Supplier
{
public int Id { get; private set; }
- public string ProductName { get; private set; } = string.Empty;
+ public string SupplierName { get; private set; } = string.Empty;
- public static Supplier CreateSupplier(int id, string productName)
+ public static Supplier CreateSupplier(int id, string supplierName)
{
return new Supplier
{
Id = id,
- ProductName = productName
+ SupplierName = supplierName
};
}
}
diff --git a/GasStation/Forms/FormSupplier.Designer.cs b/GasStation/Forms/FormSupplier.Designer.cs
index dc24570..23d8791 100644
--- a/GasStation/Forms/FormSupplier.Designer.cs
+++ b/GasStation/Forms/FormSupplier.Designer.cs
@@ -31,7 +31,7 @@
labelSupplier = new Label();
buttonSave = new Button();
buttonCancel = new Button();
- comboBoxSupplierName = new ComboBox();
+ textBoxSupplier = new TextBox();
SuspendLayout();
//
// labelSupplier
@@ -63,21 +63,19 @@
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
- // comboBoxSupplierName
+ // textBoxSupplier
//
- comboBoxSupplierName.DropDownStyle = ComboBoxStyle.DropDownList;
- comboBoxSupplierName.FormattingEnabled = true;
- comboBoxSupplierName.Location = new Point(100, 12);
- comboBoxSupplierName.Name = "comboBoxSupplierName";
- comboBoxSupplierName.Size = new Size(290, 23);
- comboBoxSupplierName.TabIndex = 4;
+ textBoxSupplier.Location = new Point(112, 9);
+ textBoxSupplier.Name = "textBoxSupplier";
+ textBoxSupplier.Size = new Size(278, 23);
+ textBoxSupplier.TabIndex = 4;
//
// FormSupplier
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(438, 122);
- Controls.Add(comboBoxSupplierName);
+ Controls.Add(textBoxSupplier);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(labelSupplier);
@@ -92,6 +90,6 @@
private Label labelSupplier;
private Button buttonSave;
private Button buttonCancel;
- private ComboBox comboBoxSupplierName;
+ private TextBox textBoxSupplier;
}
}
\ No newline at end of file
diff --git a/GasStation/Forms/FormSupplier.cs b/GasStation/Forms/FormSupplier.cs
index b85b92c..084e8c4 100644
--- a/GasStation/Forms/FormSupplier.cs
+++ b/GasStation/Forms/FormSupplier.cs
@@ -5,7 +5,7 @@ namespace GasStation.Forms
{
public partial class FormSupplier : Form
{
- private readonly ISupplierRepository _suppliarRepository;
+ private readonly ISupplierRepository _supplierRepository;
private int? _supplierId;
@@ -15,13 +15,13 @@ namespace GasStation.Forms
{
try
{
- var supplier = _suppliarRepository.ReadSupplierByID(value);
+ var supplier = _supplierRepository.ReadSupplierByID(value);
if (supplier == null)
{
throw new InvalidDataException(nameof(supplier));
}
- comboBoxSupplierName.DataSource = supplier.ProductName;
+ textBoxSupplier.Text = supplier.SupplierName;
_supplierId = value;
}
catch (Exception ex)
@@ -35,7 +35,7 @@ namespace GasStation.Forms
public FormSupplier(ISupplierRepository supplierRepository)
{
InitializeComponent();
- _suppliarRepository = supplierRepository ??
+ _supplierRepository = supplierRepository ??
throw new ArgumentNullException(nameof(supplierRepository));
}
@@ -43,17 +43,17 @@ namespace GasStation.Forms
{
try
{
- if (comboBoxSupplierName.SelectedIndex < 1)
+ if (textBoxSupplier.Text == "")
{
throw new Exception("Имеются незаполненые поля");
}
if (_supplierId.HasValue)
{
- _suppliarRepository.UpdateSupplier(CreateSupplier(_supplierId.Value));
+ _supplierRepository.UpdateSupplier(CreateSupplier(_supplierId.Value));
}
else
{
- _suppliarRepository.CreateSupplier(CreateSupplier(0));
+ _supplierRepository.CreateSupplier(CreateSupplier(0));
}
Close();
}
@@ -64,7 +64,7 @@ namespace GasStation.Forms
}
}
- private Supplier CreateSupplier(int id) => Supplier.CreateSupplier(id, comboBoxSupplierName.Text);
+ private Supplier CreateSupplier(int id) => Supplier.CreateSupplier(id, textBoxSupplier.Text);
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
}
diff --git a/GasStation/GasStation.csproj b/GasStation/GasStation.csproj
index accbdf0..7e48435 100644
--- a/GasStation/GasStation.csproj
+++ b/GasStation/GasStation.csproj
@@ -9,7 +9,18 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -27,4 +38,10 @@
+
+
+ PreserveNewest
+
+
+
\ No newline at end of file
diff --git a/GasStation/Program.cs b/GasStation/Program.cs
index 7cecfb7..5d01325 100644
--- a/GasStation/Program.cs
+++ b/GasStation/Program.cs
@@ -1,5 +1,9 @@
using GasStation.Repositories;
using GasStation.Repositories.Implementations;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Logging;
+using Serilog;
+using Unity.Microsoft.Logging;
using System.Drawing.Text;
using Unity;
@@ -23,12 +27,27 @@ internal static class Program
{
var container = new UnityContainer();
+ container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
+
container.RegisterType();
container.RegisterType();
container.RegisterType();
container.RegisterType();
container.RegisterType();
+ container.RegisterType();
return container;
}
+
+ private static LoggerFactory CreateLoggerFactory()
+ {
+ var loggerFactory = new LoggerFactory();
+ loggerFactory.AddSerilog(new LoggerConfiguration()
+ .ReadFrom.Configuration(new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("appsettings.json")
+ .Build())
+ .CreateLogger());
+ return loggerFactory;
+ }
}
\ No newline at end of file
diff --git a/GasStation/Repositories/IConnectionString.cs b/GasStation/Repositories/IConnectionString.cs
new file mode 100644
index 0000000..94781c1
--- /dev/null
+++ b/GasStation/Repositories/IConnectionString.cs
@@ -0,0 +1,6 @@
+namespace GasStation.Repositories;
+
+public interface IConnectionString
+{
+ public string ConnectionString { get; }
+}
diff --git a/GasStation/Repositories/ISellingRepository.cs b/GasStation/Repositories/ISellingRepository.cs
index 8996d8c..8d37ae3 100644
--- a/GasStation/Repositories/ISellingRepository.cs
+++ b/GasStation/Repositories/ISellingRepository.cs
@@ -8,5 +8,4 @@ public interface ISellingRepository
void CreateSelling(Selling selling);
- void DeleteSelling(int id);
}
diff --git a/GasStation/Repositories/Implementations/ConnectionString.cs b/GasStation/Repositories/Implementations/ConnectionString.cs
new file mode 100644
index 0000000..67b4120
--- /dev/null
+++ b/GasStation/Repositories/Implementations/ConnectionString.cs
@@ -0,0 +1,6 @@
+namespace GasStation.Repositories.Implementations;
+
+internal class ConnectionString : IConnectionString
+{
+ string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Username=postgres;Password=postgres;Database=normis";
+}
diff --git a/GasStation/Repositories/Implementations/GasmanRepository.cs b/GasStation/Repositories/Implementations/GasmanRepository.cs
index 43b35e9..e7e934e 100644
--- a/GasStation/Repositories/Implementations/GasmanRepository.cs
+++ b/GasStation/Repositories/Implementations/GasmanRepository.cs
@@ -1,29 +1,127 @@
using GasStation.Entities;
using GasStation.Entities.Enums;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using Npgsql;
+using Dapper;
+using System;
namespace GasStation.Repositories.Implementations;
public class GasmanRepository : IGasmanRepository
{
+ private readonly IConnectionString _connectionString;
+
+ private readonly ILogger _logger;
+
+ public GasmanRepository(IConnectionString connectionString, ILogger logger)
+ {
+ _connectionString = connectionString;
+ _logger = logger;
+ }
+
public void CreateGasman(Gasman gasman)
{
+ _logger.LogInformation("Добавление объекта");
+ _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(gasman));
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryInsert = @"
+INSERT INTO gasman (gasmanName, phoneNumber, post)
+VALUES (@GasmanName, @PhoneNumber, @Post)";
+ connection.Execute(queryInsert, gasman);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при добавлении объекта");
+ throw;
+ }
}
public void DeleteGasman(int id)
{
+ _logger.LogInformation("Удаление объекта");
+ _logger.LogDebug("Объект: {id}", id);
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryDelete = @"
+DELETE FROM gasman
+WHERE id=@id";
+ connection.Execute(queryDelete, new { id });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при удалении объекта");
+ throw;
+ }
}
public Gasman ReadGasmanByID(int id)
{
- return Gasman.CreateGasman(0, string.Empty, string.Empty, Post.None);
+ _logger.LogInformation("Получение объекта по идентификатору");
+ _logger.LogDebug("Объект: {id}", id);
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var querySelect = @"
+SELECT * FROM gasman
+WHERE id=@id";
+ var gasman = connection.QueryFirst(querySelect, new { id });
+ _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(gasman));
+
+ return gasman;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при поиске объекта");
+ throw;
+ }
}
public IEnumerable ReadGasman()
{
- return [];
+ _logger.LogInformation("Получение всех объектов");
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var querySelect = @"SELECT * FROM gasman";
+ var gasman = connection.Query(querySelect);
+ _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(gasman));
+ return gasman;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при чтении объектов");
+ throw;
+ }
}
public void UpdateGasman(Gasman gasman)
{
+ _logger.LogInformation("Редактирование объекта");
+ _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(gasman));
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryUpdate = @"
+UPDATE gasman
+SET
+ gasmanName=@GasmanName,
+ phoneNumber=@PhoneNumber,
+ post=@Post
+WHERE id=@Id";
+ connection.Execute(queryUpdate, gasman);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при редактировании объекта");
+ throw;
+ }
}
}
diff --git a/GasStation/Repositories/Implementations/ProductRepository.cs b/GasStation/Repositories/Implementations/ProductRepository.cs
index e7c03e6..fd97ba0 100644
--- a/GasStation/Repositories/Implementations/ProductRepository.cs
+++ b/GasStation/Repositories/Implementations/ProductRepository.cs
@@ -1,29 +1,126 @@
-using GasStation.Entities;
+using Dapper;
+using GasStation.Entities;
using GasStation.Entities.Enums;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using Npgsql;
namespace GasStation.Repositories.Implementations;
public class ProductRepository : IProductRepository
{
+ private readonly IConnectionString _connectionString;
+
+ private readonly ILogger _logger;
+
+ public ProductRepository(IConnectionString connectionString, ILogger logger)
+ {
+ _connectionString = connectionString;
+ _logger = logger;
+ }
+
public void CreateProduct(Product product)
{
+ _logger.LogInformation("Добавление объекта");
+ _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryInsert = @"
+INSERT INTO product (productCost, productType)
+VALUES (@ProductCost, @ProductType)";
+ connection.Execute(queryInsert, product);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при добавлении объекта");
+ throw;
+ }
}
public void DeleteProduct(int id)
{
+ _logger.LogInformation("Удаление объекта");
+ _logger.LogDebug("Объект: {id}", id);
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryDelete = @"
+DELETE FROM product
+WHERE id=@Id";
+ connection.Execute(queryDelete, new { id });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при удалении объекта");
+ throw;
+ }
}
public IEnumerable ReadProduct()
{
- return [];
+ _logger.LogInformation("Получение всех объектов");
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var querySelect = @"SELECT * FROM product";
+ var product = connection.Query(querySelect);
+ _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(product));
+ return product;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при чтении объектов");
+ throw;
+ }
+
}
public Product ReadProductByID(int id)
{
- return Product.CreateProduct(0, 0, ProductType.None);
+ _logger.LogInformation("Получение объекта по идентификатору");
+ _logger.LogDebug("Объект: {id}", id);
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var querySelect = @"
+SELECT * FROM product
+WHERE id=@Id";
+ var product = connection.QueryFirst(querySelect, new { id });
+ _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(product));
+
+ return product;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при поиске объекта");
+ throw;
+ }
}
public void UpdateProduct(Product product)
{
+ _logger.LogInformation("Редактирование объекта");
+ _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryUpdate = @"
+UPDATE product
+SET
+ productCost=@ProductCost,
+ productType=@ProductType
+WHERE id=@Id";
+ connection.Execute(queryUpdate, product);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при редактировании объекта");
+ throw;
+ }
}
}
diff --git a/GasStation/Repositories/Implementations/SellingRepository.cs b/GasStation/Repositories/Implementations/SellingRepository.cs
index a712507..7451ede 100644
--- a/GasStation/Repositories/Implementations/SellingRepository.cs
+++ b/GasStation/Repositories/Implementations/SellingRepository.cs
@@ -1,19 +1,69 @@
-using GasStation.Entities;
+using Dapper;
+using GasStation.Entities;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using Npgsql;
namespace GasStation.Repositories.Implementations;
public class SellingRepository : ISellingRepository
{
- public void CreateSelling(Selling selling)
+ private readonly IConnectionString _connectionString;
+
+ private readonly ILogger _logger;
+
+ public SellingRepository(IConnectionString connectionString, ILogger logger)
{
+ _connectionString = connectionString;
+ _logger = logger;
}
- public void DeleteSelling(int id)
+ public void CreateSelling(Selling selling)
{
+ _logger.LogInformation("Добавление объекта");
+ _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(selling));
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ connection.Open();
+ using var transaction = connection.BeginTransaction();
+ var queryInsert = @"
+INSERT INTO selling (sellingDateTime, gasmanId, count)
+VALUES (@SellingDateTime, @GasmanId, @Count);
+SELECT MAX(Id) FROM selling";
+ var Id = connection.QueryFirst(queryInsert, selling, transaction);
+ var querySubInsert = @"
+INSERT INTO product_selling (id, productID, count)
+VALUES (@Id, @ProductID, @Count)";
+ foreach (var elem in selling.ProdutcSellings)
+ {
+ connection.Execute(querySubInsert, new { Id, elem.ProductID, elem.Count }, transaction);
+ }
+ transaction.Commit();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при добавлении объекта");
+ throw;
+ }
}
public IEnumerable ReadSelling(DateTime? dateTime = null, int? count = null, int? gasmanID = null)
{
- return [];
+ _logger.LogInformation("Получение всех объектов");
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var querySelect = @"SELECT * FROM selling";
+ var selling = connection.Query(querySelect);
+ _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(selling));
+ return selling;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при чтении объектов");
+ throw;
+ }
}
}
diff --git a/GasStation/Repositories/Implementations/SupplierRepository.cs b/GasStation/Repositories/Implementations/SupplierRepository.cs
index 19bf2c0..b6b5d12 100644
--- a/GasStation/Repositories/Implementations/SupplierRepository.cs
+++ b/GasStation/Repositories/Implementations/SupplierRepository.cs
@@ -1,28 +1,123 @@
-using GasStation.Entities;
+using Dapper;
+using GasStation.Entities;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using Npgsql;
namespace GasStation.Repositories.Implementations;
public class SupplierRepository : ISupplierRepository
{
+ private readonly IConnectionString _connectionString;
+
+ private readonly ILogger _logger;
+
+ public SupplierRepository(IConnectionString connectionString, ILogger logger)
+ {
+ _connectionString = connectionString;
+ _logger = logger;
+ }
+
public void CreateSupplier(Supplier supplier)
{
+ _logger.LogInformation("Добавление объекта");
+ _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(supplier));
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryInsert = @"
+INSERT INTO supplier (supplierName)
+VALUES (@SupplierName)";
+ connection.Execute(queryInsert, supplier);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при добавлении объекта");
+ throw;
+ }
}
public void DeleteSupplier(int id)
{
+ _logger.LogInformation("Удаление объекта");
+ _logger.LogDebug("Объект: {id}", id);
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryDelete = @"
+DELETE FROM supplier
+WHERE id=@Id";
+ connection.Execute(queryDelete, new { id });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при удалении объекта");
+ throw;
+ }
}
public Supplier ReadSupplierByID(int id)
{
- return Supplier.CreateSupplier(0, string.Empty);
+ _logger.LogInformation("Получение объекта по идентификатору");
+ _logger.LogDebug("Объект: {id}", id);
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var querySelect = @"
+SELECT * FROM supplier
+WHERE id=@Id";
+ var supplier = connection.QueryFirst(querySelect, new { id });
+ _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(supplier));
+
+ return supplier;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при поиске объекта");
+ throw;
+ }
}
public IEnumerable ReadSupplier()
{
- return [];
+ _logger.LogInformation("Получение всех объектов");
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var querySelect = @"SELECT * FROM supplier";
+ var supplier = connection.Query(querySelect);
+ _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(supplier));
+ return supplier;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при чтении объектов");
+ throw;
+ }
}
public void UpdateSupplier(Supplier supplier)
{
+ _logger.LogInformation("Редактирование объекта");
+ _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(supplier));
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryUpdate = @"
+UPDATE supplier
+SET
+ supplierName=@SupplierName
+WHERE id=@Id";
+ connection.Execute(queryUpdate, supplier);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при редактировании объекта");
+ throw;
+ }
}
}
diff --git a/GasStation/Repositories/Implementations/SupplyRepository.cs b/GasStation/Repositories/Implementations/SupplyRepository.cs
index 4373fb3..13490e4 100644
--- a/GasStation/Repositories/Implementations/SupplyRepository.cs
+++ b/GasStation/Repositories/Implementations/SupplyRepository.cs
@@ -1,19 +1,78 @@
-using GasStation.Entities;
+using Dapper;
+using GasStation.Entities;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using Npgsql;
namespace GasStation.Repositories.Implementations;
public class SupplyRepository : ISupplyRepository
{
+ private readonly IConnectionString _connectionString;
+
+ private readonly ILogger _logger;
+
+ public SupplyRepository(IConnectionString connectionString, ILogger logger)
+ {
+ _connectionString = connectionString;
+ _logger = logger;
+ }
+
public void CreateSupply(Supply supply)
{
+ _logger.LogInformation("Добавление объекта");
+ _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(supply));
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryInsert = @"
+INSERT INTO supply (productID, supplierID, count, supplyDate)
+VALUES (@ProductID, @SupplierID, @Count, @SupplyDate)";
+ connection.Execute(queryInsert, supply);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при добавлении объекта");
+ throw;
+ }
}
public void DeleteSupply(int id)
{
+ _logger.LogInformation("Удаление объекта");
+ _logger.LogDebug("Объект: {id}", id);
+
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var queryDelete = @"
+DELETE FROM supply
+WHERE id=@Id";
+ connection.Execute(queryDelete, new { id });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при удалении объекта");
+ throw;
+ }
}
public IEnumerable ReadSupply(DateTime? supplyDate = null, int? supplierID = null, int? productID = null, int? count = null)
{
- return [];
+ _logger.LogInformation("Получение всех объектов");
+ try
+ {
+ using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
+ var querySelect = @"SELECT * FROM supply";
+ var supply = connection.Query(querySelect);
+ _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(supply));
+ return supply;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при чтении объектов");
+ throw;
+ }
}
}
diff --git a/GasStation/appsettings.json b/GasStation/appsettings.json
new file mode 100644
index 0000000..1de09dd
--- /dev/null
+++ b/GasStation/appsettings.json
@@ -0,0 +1,15 @@
+{
+ "Serilog": {
+ "Using": [ "Serilog.Sinks.File" ],
+ "MinimumLevel": "Debug",
+ "WriteTo": [
+ {
+ "Name": "File",
+ "Args": {
+ "path": "C:\\Users\\rozko\\Documents\\log.txt",
+ "rollinInterval": "Day"
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file