ПИбд-22 Морозов Д.В. Лабораторная 2 #7
@ -39,9 +39,9 @@ public class Order
|
||||
};
|
||||
}
|
||||
|
||||
public void AddOrderDetail(int detailId, int detailPrice, int detailCount)
|
||||
public void AddOrderDetail(int detailId, int detailCount)
|
||||
{
|
||||
var orderDetail = OrderDetail.CreateOperation(this.Id, detailId, detailPrice, detailCount);
|
||||
var orderDetail = OrderDetail.CreateOperation(this.Id, detailId, detailCount);
|
||||
OrderDetails.Add(orderDetail);
|
||||
}
|
||||
}
|
||||
|
@ -10,16 +10,14 @@ public class OrderDetail
|
||||
{
|
||||
public int OrderId { get; private set; }
|
||||
public int DetailId { get; private set; }
|
||||
public int DetailPrice { get; private set; }
|
||||
public int DetailCount { get; private set; }
|
||||
|
||||
public static OrderDetail CreateOperation(int orderId, int detailId, int detailPrice, int detailCount)
|
||||
public static OrderDetail CreateOperation(int orderId, int detailId, int detailCount)
|
||||
{
|
||||
return new OrderDetail
|
||||
{
|
||||
OrderId = orderId,
|
||||
DetailId = detailId,
|
||||
DetailPrice = detailPrice,
|
||||
DetailCount = detailCount
|
||||
};
|
||||
}
|
||||
|
@ -160,18 +160,18 @@
|
||||
//
|
||||
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBox1.Controls.Add(dataGridView);
|
||||
groupBox1.Location = new Point(30, 234);
|
||||
groupBox1.Location = new Point(25, 234);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(401, 224);
|
||||
groupBox1.TabIndex = 12;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "groupBox1";
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.AllowUserToDeleteRows = false;
|
||||
dataGridView.AllowUserToResizeColumns = false;
|
||||
dataGridView.AllowUserToResizeRows = false;
|
||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Detail, DetailCount });
|
||||
dataGridView.Location = new Point(3, 21);
|
||||
|
@ -2,6 +2,7 @@
|
||||
using ProjectRepairCompany.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -13,17 +14,50 @@ namespace ProjectRepairCompany.Forms
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly IDetailRepository _detailRepository;
|
||||
private int? _orderId;
|
||||
|
||||
public int Id
|
||||
{
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
var order = _orderRepository.ReadOrderById(value);
|
||||
if (order == null)
|
||||
{
|
||||
throw new InvalidOperationException(nameof(order));
|
||||
}
|
||||
numericUpDownFullPrice.Value = order.FullPrice;
|
||||
comboBoxMaster.SelectedValue = order.MasterId;
|
||||
dateTimeCompletion.Value = order.DateCompletion;
|
||||
dateTimeIssue.Value = order.DateIssue;
|
||||
|
||||
foreach (var detail in order.OrderDetails)
|
||||
{
|
||||
dataGridView.Rows.Add(detail.DetailId, detail.DetailCount);
|
||||
}
|
||||
|
||||
_orderId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FormOrder(IOrderRepository orderRepository, IMasterRepository masterRepository, IDetailRepository detailRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
||||
_detailRepository = detailRepository ?? throw new ArgumentNullException(nameof(detailRepository));
|
||||
|
||||
comboBoxMaster.DataSource = masterRepository.ReadMasters();
|
||||
comboBoxMaster.DisplayMember = "Name";
|
||||
comboBoxMaster.DisplayMember = "MasterName";
|
||||
comboBoxMaster.ValueMember = "Id";
|
||||
|
||||
Detail.DataSource = detailRepository.ReadDetails();
|
||||
Detail.DataSource = _detailRepository.ReadDetails();
|
||||
Detail.DisplayMember = "NameDetail";
|
||||
Detail.ValueMember = "Id";
|
||||
}
|
||||
@ -37,28 +71,27 @@ namespace ProjectRepairCompany.Forms
|
||||
throw new Exception("Имеются незаполненные поля.");
|
||||
}
|
||||
|
||||
var order = Order.CreateOperation(
|
||||
id: 0,
|
||||
fullPrice: (int)numericUpDownFullPrice.Value,
|
||||
masterId: (int)comboBoxMaster.SelectedValue!,
|
||||
dateCompletion: dateTimeCompletion.Value,
|
||||
dateIssue: dateTimeIssue.Value);
|
||||
var order = Order.CreateOperation(_orderId ?? 0, Convert.ToInt32(numericUpDownFullPrice.Value),
|
||||
(int)comboBoxMaster.SelectedValue, dateTimeCompletion.Value, dateTimeIssue.Value);
|
||||
|
||||
foreach (DataGridViewRow row in dataGridView.Rows)
|
||||
{
|
||||
if (row.Cells["Detail"].Value == null || row.Cells["DetailCount"].Value == null)
|
||||
if (row.Cells["Detail"].Value != null && row.Cells["DetailCount"].Value != null)
|
||||
{
|
||||
continue;
|
||||
var detailId = (int)row.Cells["Detail"].Value;
|
||||
var detailCount = (int)row.Cells["DetailCount"].Value;
|
||||
order.AddOrderDetail(detailId, detailCount);
|
||||
}
|
||||
|
||||
int detailId = (int)row.Cells["Detail"].Value;
|
||||
int detailCount = int.Parse(row.Cells["DetailCount"].Value.ToString() ?? "0");
|
||||
var detailPrice = (int)_detailRepository.ReadDetailById(detailId).PriceDetail;
|
||||
|
||||
order.AddOrderDetail(detailId, detailPrice, detailCount);
|
||||
}
|
||||
|
||||
_orderRepository.CreateOrder(order);
|
||||
if (_orderId.HasValue)
|
||||
{
|
||||
_orderRepository.UpdateOrder(order);
|
||||
}
|
||||
else
|
||||
{
|
||||
_orderRepository.CreateOrder(order);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
@ -68,6 +101,7 @@ namespace ProjectRepairCompany.Forms
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@
|
||||
panel1.Controls.Add(ButtonDel);
|
||||
panel1.Controls.Add(ButtonAdd);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(607, 0);
|
||||
panel1.Location = new Point(871, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(193, 450);
|
||||
panel1.TabIndex = 2;
|
||||
@ -96,14 +96,14 @@
|
||||
dataGridView.ReadOnly = true;
|
||||
dataGridView.RowHeadersVisible = false;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(607, 450);
|
||||
dataGridView.Size = new Size(871, 450);
|
||||
dataGridView.TabIndex = 3;
|
||||
//
|
||||
// FormOrders
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 17F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
ClientSize = new Size(1064, 450);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormOrders";
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectRepairCompany.Repositories;
|
||||
using ProjectRepairCompany.Entities;
|
||||
using ProjectRepairCompany.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -53,14 +54,14 @@ namespace ProjectRepairCompany.Forms
|
||||
|
||||
private void ButtonUp_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectRow(out int findId))
|
||||
if (!TryGetIdentifierFromSelectRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var form = _container.Resolve<FormMaster>();
|
||||
form.Id = findId;
|
||||
var form = _container.Resolve<FormOrder>();
|
||||
form.Id = findId;
|
||||
form.ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
@ -70,9 +71,10 @@ namespace ProjectRepairCompany.Forms
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ButtonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectRow(out int findId))
|
||||
if (!TryGetIdentifierFromSelectRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -35,7 +35,9 @@
|
||||
label3 = new Label();
|
||||
numericUpDown1 = new NumericUpDown();
|
||||
dateTimePicker1 = new DateTimePicker();
|
||||
textBox1 = new TextBox();
|
||||
comboBoxDetail = new ComboBox();
|
||||
comboBoxAddress = new ComboBox();
|
||||
label4 = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -100,19 +102,41 @@
|
||||
dateTimePicker1.Size = new Size(187, 25);
|
||||
dateTimePicker1.TabIndex = 6;
|
||||
//
|
||||
// textBox1
|
||||
// comboBoxDetail
|
||||
//
|
||||
textBox1.Location = new Point(127, 15);
|
||||
textBox1.Name = "textBox1";
|
||||
textBox1.Size = new Size(175, 25);
|
||||
textBox1.TabIndex = 7;
|
||||
comboBoxDetail.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxDetail.FormattingEnabled = true;
|
||||
comboBoxDetail.Location = new Point(128, 23);
|
||||
comboBoxDetail.Name = "comboBoxDetail";
|
||||
comboBoxDetail.Size = new Size(162, 25);
|
||||
comboBoxDetail.TabIndex = 7;
|
||||
//
|
||||
// comboBoxAddress
|
||||
//
|
||||
comboBoxAddress.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxAddress.FormattingEnabled = true;
|
||||
comboBoxAddress.Location = new Point(119, 135);
|
||||
comboBoxAddress.Name = "comboBoxAddress";
|
||||
comboBoxAddress.Size = new Size(187, 25);
|
||||
comboBoxAddress.TabIndex = 8;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(12, 143);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(91, 17);
|
||||
label4.TabIndex = 9;
|
||||
label4.Text = "Адрес склада:";
|
||||
//
|
||||
// FormStorageDetail
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 17F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(393, 435);
|
||||
Controls.Add(textBox1);
|
||||
ClientSize = new Size(393, 295);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(comboBoxAddress);
|
||||
Controls.Add(comboBoxDetail);
|
||||
Controls.Add(dateTimePicker1);
|
||||
Controls.Add(numericUpDown1);
|
||||
Controls.Add(label3);
|
||||
@ -121,7 +145,7 @@
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(ButtonSave);
|
||||
Name = "FormStorageDetail";
|
||||
Text = "FormStorageDetail";
|
||||
Text = "Пополнение склада";
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
@ -136,6 +160,8 @@
|
||||
private Label label3;
|
||||
private NumericUpDown numericUpDown1;
|
||||
private DateTimePicker dateTimePicker1;
|
||||
private TextBox textBox1;
|
||||
private ComboBox comboBoxDetail;
|
||||
private ComboBox comboBoxAddress;
|
||||
private Label label4;
|
||||
}
|
||||
}
|
@ -1,13 +1,8 @@
|
||||
using ProjectRepairCompany.Entities;
|
||||
using ProjectRepairCompany.Repositories;
|
||||
using ProjectRepairCompany.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 ProjectRepairCompany.Forms
|
||||
@ -15,86 +10,30 @@ namespace ProjectRepairCompany.Forms
|
||||
public partial class FormStorageDetail : Form
|
||||
{
|
||||
private readonly IStorageDetailRepository _storageDetailRepository;
|
||||
private readonly IDetailRepository _detailRepository;
|
||||
private int? _storageId; // ID записи для редактирования
|
||||
|
||||
public int Id
|
||||
{
|
||||
set
|
||||
{
|
||||
_storageId = value;
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
public FormStorageDetail(IStorageDetailRepository storageDetailRepository, IDetailRepository detailRepository)
|
||||
public FormStorageDetail(IStorageDetailRepository storageDetailRepository, IDetailRepository detailRepository, IStorageRepository storageRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageDetailRepository = storageDetailRepository ?? throw new ArgumentNullException(nameof(storageDetailRepository));
|
||||
_detailRepository = detailRepository ?? throw new ArgumentNullException(nameof(detailRepository));
|
||||
comboBoxDetail.DataSource = detailRepository.ReadDetails();
|
||||
comboBoxDetail.DisplayMember = "NameDetail";
|
||||
comboBoxDetail.ValueMember = "Id";
|
||||
comboBoxAddress.DataSource = storageRepository.ReadStorages();
|
||||
comboBoxAddress.DisplayMember = "StorageAddress";
|
||||
comboBoxAddress.ValueMember = "Id";
|
||||
|
||||
}
|
||||
|
||||
private void FormStorageDetailAdd_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_storageId.HasValue)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_storageId.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var storageDetail = _storageDetailRepository.ReadStorageDetails()
|
||||
.FirstOrDefault(x => x.StorageId == _storageId.Value);
|
||||
if (storageDetail == null)
|
||||
{
|
||||
throw new Exception("Запись не найдена.");
|
||||
}
|
||||
|
||||
textBox1.Text = _detailRepository.ReadDetailById(storageDetail.DetailId)?.NameDetail;
|
||||
numericUpDown1.Value = storageDetail.DetailCount;
|
||||
dateTimePicker1.Value = storageDetail.SupplyDate;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка загрузки данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Проверка на заполненность данных
|
||||
if (string.IsNullOrWhiteSpace(textBox1.Text) || numericUpDown1.Value <= 0)
|
||||
if (comboBoxDetail.SelectedIndex < 0 || comboBoxAddress.SelectedIndex < 0 || Convert.ToInt32(numericUpDown1.Value) == 0)
|
||||
{
|
||||
throw new Exception("Необходимо заполнить все поля.");
|
||||
throw new Exception("Заполни все поля");
|
||||
}
|
||||
|
||||
// Получение данных из формы
|
||||
var detail = _detailRepository.ReadDetails()
|
||||
.FirstOrDefault(d => d.NameDetail == textBox1.Text);
|
||||
|
||||
if (detail == null)
|
||||
{
|
||||
throw new Exception("Деталь с указанным названием не найдена.");
|
||||
}
|
||||
|
||||
var storageDetail = StorageDetail.CreateOperation(
|
||||
storageId: _storageId ?? 0,
|
||||
detailId: detail.Id,
|
||||
detailCount: (int)numericUpDown1.Value,
|
||||
supplyDate: dateTimePicker1.Value
|
||||
);
|
||||
|
||||
_storageDetailRepository.CreateStorageDetail(storageDetail);
|
||||
_storageDetailRepository.CreateStorageDetail(StorageDetail.CreateOperation((int)comboBoxAddress.SelectedValue!, (int)comboBoxDetail.SelectedValue!, Convert.ToInt32(numericUpDown1.Value), dateTimePicker1.Value));
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -104,6 +43,5 @@ namespace ProjectRepairCompany.Forms
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -73,15 +73,16 @@
|
||||
dataGridView.Size = new Size(607, 450);
|
||||
dataGridView.TabIndex = 4;
|
||||
//
|
||||
// FormStorageDetail
|
||||
// FormStorageDetails
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 17F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormStorageDetail";
|
||||
Text = "Пополнение деталей";
|
||||
Name = "FormStorageDetails";
|
||||
Text = "Пополнение складов";
|
||||
Load += FormStorageDetail_Load;
|
||||
panel1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
|
@ -22,7 +22,7 @@ namespace ProjectRepairCompany.Forms
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadList();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -34,7 +34,9 @@ namespace ProjectRepairCompany.Forms
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormStorageDetail>().ShowDialog(); // Форма добавления StorageDetail
|
||||
var formStorageDetail = _container.Resolve<FormStorageDetail>();
|
||||
formStorageDetail.ShowDialog();
|
||||
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -1,6 +1,10 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectRepairCompany.Repositories;
|
||||
using ProjectRepairCompany.Repositories.Implementations;
|
||||
using Serilog;
|
||||
using Unity;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
namespace ProjectRepairCompany
|
||||
{
|
||||
@ -21,12 +25,26 @@ namespace ProjectRepairCompany
|
||||
private static IUnityContainer CreateContainer()
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||
container.RegisterType<IDetailRepository, DetailRepository>();
|
||||
container.RegisterType<IMasterRepository, MasterRepository>();
|
||||
container.RegisterType<IStorageRepository, StorageRepository>();
|
||||
container.RegisterType<IStorageDetailRepository, StorageDetailRepository>();
|
||||
container.RegisterType<IOrderRepository, OrderRepository>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,18 @@
|
||||
</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="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -27,4 +38,10 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectRepairCompany.Repositories;
|
||||
|
||||
public interface IConnectionString
|
||||
{
|
||||
public string ConnectionString { get; }
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectRepairCompany.Repositories.Implementations;
|
||||
|
||||
public class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString =>
|
||||
"Host=localhost;Port=5432;Database=otp;Username=postgres;Password=postgres";
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
using ProjectRepairCompany.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectRepairCompany.Entities;
|
||||
using ProjectRepairCompany.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -10,25 +14,115 @@ namespace ProjectRepairCompany.Repositories.Implementations;
|
||||
|
||||
public class DetailRepository : IDetailRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<DetailRepository> _logger;
|
||||
|
||||
public DetailRepository(IConnectionString connectionString, ILogger<DetailRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateDetail(Detail detail)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteDetail(int id)
|
||||
{
|
||||
}
|
||||
|
||||
public Detail ReadDetailById(int id)
|
||||
{
|
||||
return Detail.CreateEntity(0, string.Empty, 0, 0, DetailProperties.None);
|
||||
}
|
||||
|
||||
public IEnumerable<Detail> ReadDetails()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(detail));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Detail (NameDetail, NumberDetail, PriceDetail, DetailProperties)
|
||||
VALUES (@NameDetail, @NumberDetail, @PriceDetail, @DetailProperties)";
|
||||
connection.Execute(queryInsert, detail);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateDetail(Detail detail)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(detail));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Detail
|
||||
SET
|
||||
NameDetail = @NameDetail,
|
||||
NumberDetail = @NumberDetail,
|
||||
PriceDetail = @PriceDetail,
|
||||
DetailProperties = @DetailProperties
|
||||
WHERE Id = @Id";
|
||||
connection.Execute(queryUpdate, detail);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка редактирования");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteDetail(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Detail
|
||||
WHERE Id = @id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Detail ReadDetailById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение по id");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Detail
|
||||
WHERE Id = @id";
|
||||
var detail = connection.QueryFirst<Detail>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(detail));
|
||||
return detail;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка поиска");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Detail> ReadDetails()
|
||||
{
|
||||
_logger.LogInformation("Получение объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Detail";
|
||||
var details = connection.Query<Detail>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(details));
|
||||
return details;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,12 @@
|
||||
using ProjectRepairCompany.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectRepairCompany.Entities;
|
||||
using ProjectRepairCompany.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,25 +15,112 @@ namespace ProjectRepairCompany.Repositories.Implementations;
|
||||
|
||||
public class MasterRepository : IMasterRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<MasterRepository> _logger;
|
||||
public MasterRepository(IConnectionString connectionString, ILogger<MasterRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateMaster(Master master)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteMaster(int id)
|
||||
{
|
||||
}
|
||||
|
||||
public Master ReadMasterById(int id)
|
||||
{
|
||||
return Master.CreateEntity(0, string.Empty, DateTime.MinValue, MasterPost.None);
|
||||
}
|
||||
|
||||
public IEnumerable<Master> ReadMasters()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Добавление обьекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(master));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Master (MasterName, StartDate, MasterPost)
|
||||
VALUES (@MasterName, @StartDate, @MasterPost)";
|
||||
connection.Execute(queryInsert, master);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateMaster(Master master)
|
||||
{
|
||||
_logger.LogInformation("Редактирование обьекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(master));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Master
|
||||
SET
|
||||
MasterName = @MasterName,
|
||||
StartDate = @StartDate,
|
||||
MasterPost = @MasterPost
|
||||
WHERE Id = @Id";
|
||||
connection.Execute(queryUpdate, master);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка Редактирования");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void DeleteMaster(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление обьекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Master
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка Удаления");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Master ReadMasterById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение по id");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Master
|
||||
WHERE Id=@id";
|
||||
var master = connection.QueryFirst<Master>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(master));
|
||||
return master;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка поиска");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Master> ReadMasters()
|
||||
{
|
||||
_logger.LogInformation("Получение объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Master";
|
||||
var master = connection.Query<Master>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(master));
|
||||
return master;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,35 +1,180 @@
|
||||
using ProjectRepairCompany.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectRepairCompany.Entities;
|
||||
using ProjectRepairCompany.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
|
||||
|
||||
namespace ProjectRepairCompany.Repositories.Implementations;
|
||||
|
||||
public class OrderRepository : IOrderRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<OrderRepository> _logger;
|
||||
|
||||
public OrderRepository(IConnectionString connectionString, ILogger<OrderRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateOrder(Order order)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(order));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO ""Order"" (OrderDate, DateCompletion, DateIssue, FullPrice, MasterId)
|
||||
VALUES (@OrderDate, @DateCompletion, @DateIssue, @FullPrice, @MasterId);
|
||||
SELECT MAX(Id) FROM ""Order""";
|
||||
var orderId = connection.QueryFirst<int>(queryInsert, order, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO OrderDetail (OrderId, DetailId, DetailCount)
|
||||
VALUES (@OrderId, @DetailId, @DetailCount)";
|
||||
foreach (var elem in order.OrderDetails)
|
||||
{
|
||||
connection.Execute(querySubInsert, new {orderId, elem.DetailId, elem.DetailCount}, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateOrder(Order order)
|
||||
{
|
||||
_logger.LogInformation("Обновление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(order));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
|
||||
var queryUpdate = @"
|
||||
UPDATE ""Order""
|
||||
SET DateCompletion = @DateCompletion,
|
||||
DateIssue = @DateIssue,
|
||||
FullPrice = @FullPrice,
|
||||
MasterId = @MasterId
|
||||
WHERE Id = @Id";
|
||||
|
||||
connection.Execute(queryUpdate, new
|
||||
{
|
||||
order.Id,
|
||||
order.DateCompletion,
|
||||
order.DateIssue,
|
||||
order.FullPrice,
|
||||
order.MasterId
|
||||
}, transaction);
|
||||
|
||||
var queryDeleteDetails = "DELETE FROM OrderDetail WHERE OrderId = @OrderId";
|
||||
connection.Execute(queryDeleteDetails, new { order.Id }, transaction);
|
||||
|
||||
var queryInsertDetails = @"
|
||||
INSERT INTO OrderDetail (OrderId, DetailId, DetailCount)
|
||||
VALUES (@OrderId, @DetailId, @DetailCount)";
|
||||
|
||||
foreach (var detail in order.OrderDetails)
|
||||
{
|
||||
connection.Execute(queryInsertDetails, new
|
||||
{
|
||||
order.Id,
|
||||
detail.DetailId,
|
||||
detail.DetailCount
|
||||
}, transaction);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при обновлении");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void DeleteOrder(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта с Id {OrderId}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
|
||||
var queryDeleteDetails = "DELETE FROM OrderDetail WHERE OrderId = @OrderId";
|
||||
connection.Execute(queryDeleteDetails, new { OrderId = id }, transaction);
|
||||
|
||||
var queryDeleteOrder = "DELETE FROM \"Order\" WHERE Id = @Id";
|
||||
connection.Execute(queryDeleteOrder, new { Id = id }, transaction);
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Order ReadOrderById(int id)
|
||||
{
|
||||
return Order.CreateOperation(0, 0, 0, DateTime.MinValue, DateTime.MinValue);
|
||||
_logger.LogInformation("Получение по id");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM ""Order""
|
||||
WHERE Id=@id";
|
||||
var order = connection.QueryFirst<Order>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(order));
|
||||
return order;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка поиска");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IEnumerable<Order> ReadOrders()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
public void UpdateOrder(Order order)
|
||||
{
|
||||
var querySelect = @"SELECT * FROM ""Order""";
|
||||
var orders = connection.Query<Order>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orders));
|
||||
return orders;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,20 +1,62 @@
|
||||
using ProjectRepairCompany.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectRepairCompany.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
|
||||
|
||||
namespace ProjectRepairCompany.Repositories.Implementations;
|
||||
|
||||
public class StorageDetailRepository : IStorageDetailRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<StorageDetailRepository> _logger;
|
||||
|
||||
public StorageDetailRepository(IConnectionString connectionString, ILogger<StorageDetailRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateStorageDetail(StorageDetail storageDetail)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(storageDetail));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO StorageDetail (StorageId, DetailId, DetailCount, SupplyDate)
|
||||
VALUES (@StorageId, @DetailId, @DetailCount, @SupplyDate)";
|
||||
connection.Execute(queryInsert, storageDetail);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<StorageDetail> ReadStorageDetails(DateTime? dateFrom = null, DateTime? dateTo = null, int? storageId = null, int? detailId = null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM StorageDetail";
|
||||
var storageDetails = connection.Query<StorageDetail>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(storageDetails));
|
||||
return storageDetails;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
using ProjectRepairCompany.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using ProjectRepairCompany.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Npgsql;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,25 +13,110 @@ namespace ProjectRepairCompany.Repositories.Implementations;
|
||||
|
||||
public class StorageRepository : IStorageRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<StorageRepository> _logger;
|
||||
public StorageRepository(IConnectionString connectionString, ILogger<StorageRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateStorage(Storage storage)
|
||||
{
|
||||
_logger.LogInformation("Добавление обьекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(storage));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Storage (StorageAddress, Capacity)
|
||||
VALUES (@StorageAddress, @Capacity)";
|
||||
connection.Execute(queryInsert, storage);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateStorage(Storage storage)
|
||||
{
|
||||
_logger.LogInformation("Редактирование обьекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(storage));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Storage
|
||||
SET
|
||||
StorageAddress = @StorageAddress,
|
||||
Capacity = @Capacity
|
||||
WHERE Id = @Id";
|
||||
connection.Execute(queryUpdate, storage);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка Редактирования");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteStorage(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление обьекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Storage
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new {id});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка Удаления");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Storage ReadStorageById(int id)
|
||||
{
|
||||
return Storage.CreateEntity(0, string.Empty, 0);
|
||||
_logger.LogInformation("Получение по id");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Storage
|
||||
WHERE Id=@id";
|
||||
var storage = connection.QueryFirst<Storage>(querySelect, new {id});
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(storage));
|
||||
return storage;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка поиска");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Storage> ReadStorages()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Storage";
|
||||
var storage = connection.Query<Storage>(querySelect).ToList();
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(storage));
|
||||
return storage;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateStorage(Storage storage)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
16
ProjectRepairCompany/ProjectRepairCompany/appsettings.json
Normal file
16
ProjectRepairCompany/ProjectRepairCompany/appsettings.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logo/repairCompany_log.txt",
|
||||
"rollingInterval": "Day"
|
||||
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user