PIbd-22_Ulybin_A.A._FuelAccounting_Lab02 #5
@ -1,13 +1,4 @@
|
||||
using FuelAccounting.Forms;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Unity;
|
||||
|
||||
namespace FuelAccounting
|
||||
|
@ -123,6 +123,7 @@
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Name = "FormCar";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Автомобиль";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
|
@ -24,7 +24,7 @@ namespace FuelAccounting.Forms
|
||||
|
||||
textBoxModel.Text = car.Model;
|
||||
comboBoxCategory.SelectedItem = car.Category;
|
||||
comboBoxDriverId.SelectedItem = car.DriverID;
|
||||
comboBoxDriverId.SelectedValue = car.DriverID;
|
||||
_carId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -80,6 +80,6 @@ namespace FuelAccounting.Forms
|
||||
private Car CreateCar(int id) =>
|
||||
Car.CreateEntity(id, textBoxModel.Text,
|
||||
(CarCategory)comboBoxCategory.SelectedItem!,
|
||||
(int)comboBoxDriverId.SelectedItem!);
|
||||
(int)comboBoxDriverId.SelectedValue!);
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +106,7 @@
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panelButtons);
|
||||
Name = "FormCars";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Автомобили";
|
||||
Load += FormCars_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
||||
|
@ -121,6 +121,7 @@
|
||||
Controls.Add(label1);
|
||||
Controls.Add(checkedListBoxDriverLicenceCategory);
|
||||
Name = "FormDriver";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "FormDriver";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
|
@ -1,7 +1,6 @@
|
||||
using FuelAccounting.Entities;
|
||||
using FuelAccounting.Entities.Enums;
|
||||
using FuelAccounting.Repositories;
|
||||
using FuelAccounting.Repositories.Implementations;
|
||||
|
||||
namespace FuelAccounting.Forms
|
||||
{
|
||||
@ -72,7 +71,7 @@ namespace FuelAccounting.Forms
|
||||
}
|
||||
else
|
||||
{
|
||||
_driverRepository.UpdateDriver(CreateDriver(0));
|
||||
_driverRepository.CreateDriver(CreateDriver(0));
|
||||
}
|
||||
|
||||
Close();
|
||||
|
@ -106,6 +106,7 @@
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panelButtons);
|
||||
Name = "FormDrivers";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Водители";
|
||||
Load += FormDrivers_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
||||
|
@ -1,14 +1,4 @@
|
||||
using FuelAccounting.Repositories;
|
||||
using FuelAccounting.Repositories.Implementations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Unity;
|
||||
|
||||
namespace FuelAccounting.Forms
|
||||
|
@ -169,6 +169,7 @@
|
||||
Controls.Add(comboBoxCar);
|
||||
Controls.Add(label1);
|
||||
Name = "FormEquipage";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Выезд";
|
||||
groupBoxRoutes.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).EndInit();
|
||||
|
@ -1,15 +1,5 @@
|
||||
using FuelAccounting.Entities;
|
||||
using FuelAccounting.Repositories;
|
||||
using FuelAccounting.Repositories.Implementations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FuelAccounting.Forms
|
||||
{
|
||||
|
@ -30,8 +30,8 @@
|
||||
{
|
||||
dataGridViewData = new DataGridView();
|
||||
panelButtons = new Panel();
|
||||
buttonAdd = new Button();
|
||||
buttonDelete = new Button();
|
||||
buttonAdd = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
|
||||
panelButtons.SuspendLayout();
|
||||
SuspendLayout();
|
||||
@ -63,17 +63,6 @@
|
||||
panelButtons.Size = new Size(160, 450);
|
||||
panelButtons.TabIndex = 10;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackgroundImage = Properties.Resources.pngimg_com___plus_PNG84;
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(18, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(130, 130);
|
||||
buttonAdd.TabIndex = 2;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += ButtonAdd_Click;
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
buttonDelete.BackgroundImage = Properties.Resources.images;
|
||||
@ -85,6 +74,17 @@
|
||||
buttonDelete.UseVisualStyleBackColor = true;
|
||||
buttonDelete.Click += ButtonDelete_Click;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackgroundImage = Properties.Resources.pngimg_com___plus_PNG84;
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(18, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(130, 130);
|
||||
buttonAdd.TabIndex = 2;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += ButtonAdd_Click;
|
||||
//
|
||||
// FormEquipages
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -93,6 +93,7 @@
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panelButtons);
|
||||
Name = "FormEquipages";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Выезды";
|
||||
Load += FormEquipages_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
||||
|
@ -1,14 +1,4 @@
|
||||
using FuelAccounting.Repositories;
|
||||
using FuelAccounting.Repositories.Implementations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Unity;
|
||||
|
||||
namespace FuelAccounting.Forms
|
||||
|
@ -74,7 +74,7 @@
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(12, 126);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(75, 15);
|
||||
label4.Size = new Size(76, 15);
|
||||
label4.TabIndex = 3;
|
||||
label4.Text = "Тип топлива";
|
||||
//
|
||||
@ -131,7 +131,7 @@
|
||||
buttonSave.TabIndex = 10;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
buttonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// FormRefueling
|
||||
//
|
||||
@ -149,6 +149,7 @@
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Name = "FormRefueling";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "FormRefueling";
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownKm).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownLiters).EndInit();
|
||||
|
@ -1,14 +1,5 @@
|
||||
using FuelAccounting.Entities;
|
||||
using FuelAccounting.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FuelAccounting.Forms
|
||||
{
|
||||
@ -27,7 +18,7 @@ namespace FuelAccounting.Forms
|
||||
comboBoxCar.ValueMember = "Id";
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -38,7 +29,7 @@ namespace FuelAccounting.Forms
|
||||
}
|
||||
|
||||
_refuelingRepository.CreateRefueling(Refueling.CreateOperation(0, (int)comboBoxCar.SelectedValue!,
|
||||
Convert.ToDouble(numericUpDownKm), Convert.ToDouble(numericUpDownLiters), textBoxTypeOfFuel.Text));
|
||||
Convert.ToDouble(numericUpDownKm.Value), Convert.ToDouble(numericUpDownLiters.Value), textBoxTypeOfFuel.Text));
|
||||
|
||||
Close();
|
||||
}
|
||||
|
@ -80,6 +80,7 @@
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panelButtons);
|
||||
Name = "FormRefuelings";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Заправки";
|
||||
Load += FormRefuelings_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
||||
|
@ -1,14 +1,4 @@
|
||||
using FuelAccounting.Repositories;
|
||||
using FuelAccounting.Repositories.Implementations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Unity;
|
||||
|
||||
namespace FuelAccounting.Forms
|
||||
|
@ -1,14 +1,5 @@
|
||||
using FuelAccounting.Entities;
|
||||
using FuelAccounting.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FuelAccounting.Forms
|
||||
{
|
||||
|
@ -1,13 +1,4 @@
|
||||
using FuelAccounting.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Unity;
|
||||
|
||||
namespace FuelAccounting.Forms
|
||||
|
@ -1,14 +1,5 @@
|
||||
using FuelAccounting.Entities;
|
||||
using FuelAccounting.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FuelAccounting.Forms
|
||||
{
|
||||
|
@ -106,6 +106,7 @@
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panelButtons);
|
||||
Name = "FormShifts";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Смены";
|
||||
Load += FormShifts_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
||||
|
@ -9,7 +9,19 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="9.0.1" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -27,4 +39,10 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,7 +1,10 @@
|
||||
using FuelAccounting.Repositories;
|
||||
using FuelAccounting.Repositories.Implementations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Unity;
|
||||
using Unity.Lifetime;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
namespace FuelAccounting;
|
||||
|
||||
@ -23,13 +26,28 @@ internal static class Program
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container.RegisterType<ICarsRepository, CarRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IDriversRepository, DriverRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IRouteRepository, RouteRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IShiftRepository, ShiftRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IEquipageRepository, EquipageRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IRefuelingRepository, RefuelingRepository>(new TransientLifetimeManager());
|
||||
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||
|
||||
container.RegisterType<ICarsRepository, CarRepository>();
|
||||
container.RegisterType<IDriversRepository, DriverRepository>();
|
||||
container.RegisterType<IRouteRepository, RouteRepository>();
|
||||
container.RegisterType<IShiftRepository, ShiftRepository>();
|
||||
container.RegisterType<IEquipageRepository, EquipageRepository>();
|
||||
container.RegisterType<IRefuelingRepository, RefuelingRepository>();
|
||||
container.RegisterType<IConnectionString, ConnectionString>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -80,16 +80,6 @@ namespace FuelAccounting.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap Cancel {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("Cancel", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
@ -100,37 +90,6 @@ namespace FuelAccounting.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap png_clipart_plus_plus {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("png-clipart-plus-plus", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap png_clipart_plus_plus__1_ {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("png-clipart-plus-plus (1)", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap png_transparent_pencil_illustration_hand_painted_pencil_material_watercolor_painting_text_color_pencil {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("png-transparent-pencil-illustration-hand-painted-pencil-material-watercolor-paint" +
|
||||
"ing-text-color-pencil", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
|
@ -118,15 +118,6 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="png-clipart-plus-plus" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\png-clipart-plus-plus.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="png-transparent-pencil-illustration-hand-painted-pencil-material-watercolor-painting-text-color-pencil" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\png-transparent-pencil-illustration-hand-painted-pencil-material-watercolor-painting-text-color-pencil.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="Cancel" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\Cancel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="pngimg.com - plus_PNG84" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\pngimg.com - plus_PNG84.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
@ -136,9 +127,6 @@
|
||||
<data name="4298" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\4298.jpeg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="png-clipart-plus-plus (1)" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\png-clipart-plus-plus (1).png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="images" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\images.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
|
@ -0,0 +1,6 @@
|
||||
namespace FuelAccounting.Repositories;
|
||||
|
||||
public interface IConnectionString
|
||||
{
|
||||
public string ConnectionString { get; }
|
||||
}
|
@ -1,29 +1,130 @@
|
||||
using FuelAccounting.Entities;
|
||||
using FuelAccounting.Entities.Enums;
|
||||
using Dapper;
|
||||
using FuelAccounting.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
|
||||
namespace FuelAccounting.Repositories.Implementations;
|
||||
|
||||
internal class CarRepository : ICarsRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<CarRepository> _logger;
|
||||
|
||||
public CarRepository(IConnectionString connectionString, ILogger<CarRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateCar(Car car)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteCar(int id)
|
||||
{
|
||||
}
|
||||
|
||||
public Car ReadCarById(int id)
|
||||
{
|
||||
return Car.CreateEntity(0, string.Empty, CarCategory.None, 0);
|
||||
}
|
||||
|
||||
public IEnumerable<Car> ReadCars()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(car));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Cars (model, category, driver_id)
|
||||
VALUES (@Model, @Category, @DriverID)";
|
||||
connection.Execute(queryInsert, car);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCar(Car car)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(car));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Cars
|
||||
SET
|
||||
model = @model,
|
||||
category = @category,
|
||||
driver_id = @DriverID
|
||||
WHERE id = @id";
|
||||
connection.Execute(queryUpdate, car);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteCar(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Cars
|
||||
WHERE id = @id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Car ReadCarById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT
|
||||
model,
|
||||
category,
|
||||
driver_id AS DriverID
|
||||
FROM Cars
|
||||
WHERE id = @id";
|
||||
var car = connection.QueryFirst<Car>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(car));
|
||||
return car;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Car> ReadCars()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT
|
||||
id,
|
||||
model,
|
||||
category,
|
||||
driver_id AS DriverID
|
||||
FROM Cars";
|
||||
var cars = connection.Query<Car>(querySelect);
|
||||
_logger.LogDebug("Найденные объекты: {json}", JsonConvert.SerializeObject(cars));
|
||||
return cars;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
namespace FuelAccounting.Repositories.Implementations;
|
||||
|
||||
internal class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "host=localhost;port=5432;database=postgres;username=postgres;password=postgres";
|
||||
}
|
@ -1,29 +1,130 @@
|
||||
using FuelAccounting.Entities;
|
||||
using FuelAccounting.Entities.Enums;
|
||||
using Dapper;
|
||||
using FuelAccounting.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
|
||||
namespace FuelAccounting.Repositories.Implementations;
|
||||
|
||||
internal class DriverRepository : IDriversRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<DriverRepository> _logger;
|
||||
|
||||
public DriverRepository(IConnectionString connectionString, ILogger<DriverRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateDriver(Driver driver)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteDriver(int id)
|
||||
{
|
||||
}
|
||||
|
||||
public Driver ReadDriverById(int id)
|
||||
{
|
||||
return Driver.CreateEntity(0, string.Empty, string.Empty, DriverLicenceCategory.None);
|
||||
}
|
||||
|
||||
public IEnumerable<Driver> ReadDrivers()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(driver));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Drivers (first_name, last_name, driver_licence_category)
|
||||
VALUES (@FirstName, @LastName, @DriverLicenceCategory)";
|
||||
connection.Execute(queryInsert, driver);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateDriver(Driver driver)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(driver));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Drivers
|
||||
SET
|
||||
first_name = @FirstName,
|
||||
last_name = @LastName,
|
||||
driver_licence_category = @DriverLicenceCategory
|
||||
WHERE id = @Id";
|
||||
connection.Execute(queryUpdate, driver);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteDriver(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Drivers
|
||||
WHERE id = @id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Driver ReadDriverById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT
|
||||
first_name AS FirstName,
|
||||
last_name AS LastName,
|
||||
driver_licence_category AS DriverLicenceCategory
|
||||
FROM Drivers
|
||||
WHERE id = @Id";
|
||||
var driver = connection.QueryFirst<Driver>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(driver));
|
||||
return driver;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Driver> ReadDrivers()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT
|
||||
id,
|
||||
first_name AS FirstName,
|
||||
last_name AS LastName,
|
||||
driver_licence_category AS DriverLicenceCategory
|
||||
FROM Drivers";
|
||||
var drivers = connection.Query<Driver>(querySelect);
|
||||
_logger.LogDebug("Найденные объекты: {json}", JsonConvert.SerializeObject(drivers));
|
||||
return drivers;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,101 @@
|
||||
using FuelAccounting.Entities;
|
||||
using Dapper;
|
||||
using FuelAccounting.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
|
||||
namespace FuelAccounting.Repositories.Implementations;
|
||||
|
||||
internal class EquipageRepository : IEquipageRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<EquipageRepository> _logger;
|
||||
|
||||
public EquipageRepository(IConnectionString connectionString, ILogger<EquipageRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateEquipage(Equipage equipage)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(equipage));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
|
||||
var queryInsert = @"
|
||||
INSERT INTO Equipage (car_id, driver_id, shift_id, equipage_date)
|
||||
VALUES (@CarId, @DriverId, @ShiftId, @EquipageDate)";
|
||||
connection.Execute(queryInsert, equipage, transaction);
|
||||
|
||||
var queryGetLastId = "SELECT MAX(Id) FROM Equipage";
|
||||
var equipageId = connection.QueryFirst<int>(queryGetLastId, transaction: transaction);
|
||||
|
||||
var querySubInsert = @"
|
||||
INSERT INTO RoutesEquipage (equipage_id, route_id, count)
|
||||
VALUES (@EquipageId, @RouteId, @Count)";
|
||||
foreach (var elem in equipage.RoutesEqipage)
|
||||
{
|
||||
connection.Execute(querySubInsert, new { EquipageId = equipageId, elem.RouteID, elem.Count }, transaction);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void DeleteEquipage(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Equipage
|
||||
WHERE id = @id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Equipage> ReadEquipages(DateTime? dateForm = null, DateTime? dateTo = null,
|
||||
int? carId = null, int? driverId = null, int? shiftId = null, int? routeId = null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT
|
||||
id,
|
||||
car_id AS CarId,
|
||||
driver_id AS DriverId,
|
||||
shift_id AS ShiftId,
|
||||
equipage_date AS EquipageDate
|
||||
FROM Equipage";
|
||||
var equipages = connection.Query<Equipage>(querySelect);
|
||||
_logger.LogDebug("Найденные объекты: {json}", JsonConvert.SerializeObject(equipages));
|
||||
return equipages;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,65 @@
|
||||
using FuelAccounting.Entities;
|
||||
using Dapper;
|
||||
using FuelAccounting.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
|
||||
namespace FuelAccounting.Repositories.Implementations;
|
||||
|
||||
internal class RefuelingRepository : IRefuelingRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<RefuelingRepository> _logger;
|
||||
|
||||
public RefuelingRepository(IConnectionString connectionString, ILogger<RefuelingRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateRefueling(Refueling refueling)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(refueling));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Refueling (car_id, km, liters_spent, type_of_fuel, refueling_date)
|
||||
VALUES (@CarId, @Kilometers, @LitersSpent, @TypeOfFuel, @RefuelingDate)";
|
||||
connection.Execute(queryInsert, refueling);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Refueling> ReadRefuelings(DateTime? dateForm = null, DateTime? dateTo = null, int? carId = null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT
|
||||
id,
|
||||
car_id AS CarId,
|
||||
km AS Kilometers,
|
||||
liters_spent AS LitersSpent,
|
||||
type_of_fuel AS TypeOfFuel,
|
||||
refueling_date AS RefuelingDate
|
||||
FROM Refueling";
|
||||
var refuelings = connection.Query<Refueling>(querySelect);
|
||||
_logger.LogDebug("Найденные объекты: {json}", JsonConvert.SerializeObject(refuelings));
|
||||
return refuelings;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,119 @@
|
||||
using FuelAccounting.Entities;
|
||||
using Dapper;
|
||||
using FuelAccounting.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
|
||||
namespace FuelAccounting.Repositories.Implementations;
|
||||
|
||||
internal class RouteRepository : IRouteRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<RouteRepository> _logger;
|
||||
|
||||
public RouteRepository(IConnectionString connectionString, ILogger<RouteRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateRoute(Route route)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteRoute(int id)
|
||||
{
|
||||
}
|
||||
|
||||
public Route ReadRouteById(int id)
|
||||
{
|
||||
return Route.CreateEntity(0, string.Empty);
|
||||
}
|
||||
|
||||
public IEnumerable<Route> ReadRoutes()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(route));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Routes (description)
|
||||
VALUES (@description)";
|
||||
connection.Execute(queryInsert, route);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateRoute(Route route)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(route));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Routes
|
||||
SET
|
||||
description = @description
|
||||
WHERE id = @Id";
|
||||
connection.Execute(queryUpdate, route);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteRoute(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Routes
|
||||
WHERE id = @id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Route ReadRouteById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Routes
|
||||
WHERE id = @Id";
|
||||
var route = connection.QueryFirst<Route>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(route));
|
||||
return route;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Route> ReadRoutes()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Routes";
|
||||
var routes = connection.Query<Route>(querySelect);
|
||||
_logger.LogDebug("Найденные объекты: {json}", JsonConvert.SerializeObject(routes));
|
||||
return routes;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,28 +1,128 @@
|
||||
using FuelAccounting.Entities;
|
||||
using Dapper;
|
||||
using FuelAccounting.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
|
||||
namespace FuelAccounting.Repositories.Implementations;
|
||||
|
||||
internal class ShiftRepository : IShiftRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<ShiftRepository> _logger;
|
||||
|
||||
public ShiftRepository(IConnectionString connectionString, ILogger<ShiftRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateShift(Shift shift)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteShift(int id)
|
||||
{
|
||||
}
|
||||
|
||||
public Shift ReadShiftById(int id)
|
||||
{
|
||||
return Shift.CreateEntity(0, 0, string.Empty);
|
||||
}
|
||||
|
||||
public IEnumerable<Shift> ReadShifts()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(shift));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Shift (amount_of_hours, description)
|
||||
VALUES (@AmountOfHours, @Description)";
|
||||
connection.Execute(queryInsert, shift);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateShift(Shift shift)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(shift));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Shift
|
||||
SET
|
||||
amount_of_hours = @AmountOfHours,
|
||||
description = @Description
|
||||
WHERE id = @Id";
|
||||
connection.Execute(queryUpdate, shift);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteShift(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Shift
|
||||
WHERE id = @id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Shift ReadShiftById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT
|
||||
amount_of_hours AS AmountOfHours,
|
||||
description
|
||||
FROM Shift
|
||||
WHERE id = @Id";
|
||||
var shift = connection.QueryFirst<Shift>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(shift));
|
||||
return shift;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Shift> ReadShifts()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT
|
||||
id,
|
||||
amount_of_hours AS AmountOfHours,
|
||||
description
|
||||
FROM Shift";
|
||||
var shift = connection.Query<Shift>(querySelect);
|
||||
_logger.LogDebug("Найденные объекты: {json}", JsonConvert.SerializeObject(shift));
|
||||
return shift;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 236 KiB |
Binary file not shown.
Before Width: | Height: | Size: 18 KiB |
Binary file not shown.
Before Width: | Height: | Size: 30 KiB |
Binary file not shown.
Before Width: | Height: | Size: 23 KiB |
15
FuelAccounting/FuelAccounting/appsettings.json
Normal file
15
FuelAccounting/FuelAccounting/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/fuel_log.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user