ПИбд-23. Кадышев М.И. Лабораторная работа 2 #2
@ -15,9 +15,9 @@ public class Accessories
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Price { get; private set; }
|
||||
public float Price { get; private set; }
|
||||
|
||||
public static Accessories CreateEntity(int id, AccessoriesType accessoriesType, int count, double price)
|
||||
public static Accessories CreateEntity(int id, AccessoriesType accessoriesType, int count, float price)
|
||||
{
|
||||
return new Accessories
|
||||
{
|
||||
|
@ -23,15 +23,17 @@ public class Order
|
||||
public IEnumerable<ServicesOrder> ServicesOrders { get; private set; } = [];
|
||||
|
||||
|
||||
public static Order CreateElement(int id, string name, string coment, int masterId)
|
||||
public static Order CreateElement(int id, string name,DateTime date, string coment, int masterId, IEnumerable<AccessoiresOrder> accessoiresOrders, IEnumerable<ServicesOrder> servicesOrder)
|
||||
{
|
||||
return new Order()
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Coment = coment,
|
||||
Date = DateTime.Now,
|
||||
MasterID = masterId
|
||||
Date = date,
|
||||
MasterID = masterId,
|
||||
AccessoiresOrders = accessoiresOrders,
|
||||
ServicesOrders = servicesOrder
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ public class Service
|
||||
|
||||
public ServiceType ServiceType { get; private set; }
|
||||
|
||||
public double Price { get; private set; }
|
||||
public float Price { get; private set; }
|
||||
|
||||
public static Service CreateEntity(int id, ServiceType serviceType, double price)
|
||||
public static Service CreateEntity(int id, ServiceType serviceType, float price)
|
||||
{
|
||||
return new Service
|
||||
{
|
||||
|
@ -74,15 +74,13 @@ namespace ProjectCompRepair.Forms
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
private Accessories CreateAccessories(int id)
|
||||
{
|
||||
return Accessories.CreateEntity(id, (AccessoriesType)comboBoxType.SelectedItem! , (int)numericUpDownCount.Value, (double)numericUpDownPrice.Value);
|
||||
private Accessories CreateAccessories(int id) => Accessories.CreateEntity(id, (AccessoriesType)comboBoxType.SelectedItem! , (int)numericUpDownCount.Value, (float)numericUpDownPrice.Value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public partial class FormMaster : Form
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
@ -70,14 +70,14 @@ public partial class FormOrder : Form
|
||||
{
|
||||
throw new Exception("Имеются незаполненые поля");
|
||||
}
|
||||
_orderRepository.CreateOrder(Order.CreateElement(0, textBoxName.Text, textBoxComent.Text, (int)comboBoxMaster.SelectedValue!));
|
||||
_orderRepository.CreateOrder(Order.CreateElement(0, textBoxName.Text,dateTimePicker.Value, textBoxComent.Text, (int)comboBoxMaster.SelectedValue!, CreateListAccessoiresOrderFromDataGrid(), CreateListServicesOrderFromDataGrid()));
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
@ -87,13 +87,13 @@ public partial class FormOrder : Form
|
||||
var list = new List<AccessoiresOrder>();
|
||||
foreach (DataGridViewRow row in dataGridViewAccessories.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnAccessoires"].Value == null ||
|
||||
if (row.Cells["ColumnAccessories"].Value == null ||
|
||||
row.Cells["ColumnCount"].Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.Add(AccessoiresOrder.CreateElement(0,
|
||||
Convert.ToInt32(row.Cells["ColumnAccessoires"].Value),
|
||||
Convert.ToInt32(row.Cells["ColumnAccessories"].Value),
|
||||
Convert.ToInt32(row.Cells["ColumnCount"].Value)));
|
||||
}
|
||||
return list;
|
||||
@ -102,16 +102,16 @@ public partial class FormOrder : Form
|
||||
private List<ServicesOrder> CreateListServicesOrderFromDataGrid()
|
||||
{
|
||||
var list = new List<ServicesOrder>();
|
||||
foreach (DataGridViewRow row in dataGridViewAccessories.Rows)
|
||||
foreach (DataGridViewRow row in dataGridViewServices.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnServices"].Value == null ||
|
||||
row.Cells["ColumnCountServices"].Value == null)
|
||||
if (row.Cells["ColumnService"].Value == null ||
|
||||
row.Cells["ColumnCountServ"].Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.Add(ServicesOrder.CreateElement(0,
|
||||
Convert.ToInt32(row.Cells["ColumnAccessoires"].Value),
|
||||
Convert.ToInt32(row.Cells["ColumnCount"].Value)));
|
||||
Convert.ToInt32(row.Cells["ColumnService"].Value),
|
||||
Convert.ToInt32(row.Cells["ColumnCountServ"].Value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -123,18 +123,6 @@
|
||||
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnAccessories.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnService.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnCountServ.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnService.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
|
@ -29,7 +29,6 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonDel = new Button();
|
||||
buttonChange = new Button();
|
||||
buttonCreate = new Button();
|
||||
dataGridView = new DataGridView();
|
||||
panelButtons = new Panel();
|
||||
@ -41,24 +40,13 @@
|
||||
//
|
||||
buttonDel.BackgroundImage = Properties.Resources.pngwing_com__7_;
|
||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDel.Location = new Point(40, 255);
|
||||
buttonDel.Location = new Point(40, 173);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(94, 91);
|
||||
buttonDel.TabIndex = 2;
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += ButtonDel_Click;
|
||||
//
|
||||
// buttonChange
|
||||
//
|
||||
buttonChange.BackgroundImage = Properties.Resources.pngwing_com__8_;
|
||||
buttonChange.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonChange.Location = new Point(40, 149);
|
||||
buttonChange.Name = "buttonChange";
|
||||
buttonChange.Size = new Size(94, 89);
|
||||
buttonChange.TabIndex = 1;
|
||||
buttonChange.UseVisualStyleBackColor = true;
|
||||
buttonChange.Click += ButtonChange_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.BackgroundImage = Properties.Resources.pngwing_com__6_;
|
||||
@ -83,7 +71,6 @@
|
||||
// panelButtons
|
||||
//
|
||||
panelButtons.Controls.Add(buttonDel);
|
||||
panelButtons.Controls.Add(buttonChange);
|
||||
panelButtons.Controls.Add(buttonCreate);
|
||||
panelButtons.Dock = DockStyle.Right;
|
||||
panelButtons.Location = new Point(545, 0);
|
||||
@ -109,7 +96,6 @@
|
||||
#endregion
|
||||
|
||||
private Button buttonDel;
|
||||
private Button buttonChange;
|
||||
private Button buttonCreate;
|
||||
private DataGridView dataGridView;
|
||||
private Panel panelButtons;
|
||||
|
@ -41,6 +41,7 @@ namespace ProjectCompRepair.Forms
|
||||
}
|
||||
|
||||
_service = value;
|
||||
numericUpDownPrice.Value = (int)service.Price;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -100,7 +101,7 @@ namespace ProjectCompRepair.Forms
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
@ -112,7 +113,7 @@ namespace ProjectCompRepair.Forms
|
||||
{
|
||||
serviceType |= (ServiceType)elem;
|
||||
}
|
||||
return Service.CreateEntity(id, serviceType, (double)numericUpDownPrice.Value);
|
||||
return Service.CreateEntity(id, serviceType, (float)numericUpDownPrice.Value);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ namespace ProjectCompRepair.Forms
|
||||
}
|
||||
try
|
||||
{
|
||||
var form = _container.Resolve<FormMaster>();
|
||||
var form = _container.Resolve<FormService>();
|
||||
form.Id = findId;
|
||||
form.ShowDialog();
|
||||
LoadList();
|
||||
|
@ -1,7 +1,14 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectCompRepair.Repositories;
|
||||
using ProjectCompRepair.Repositories.Implemantations;
|
||||
using Serilog;
|
||||
using System;
|
||||
using Unity;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Unity.Microsoft.Logging;
|
||||
using Unity.Lifetime;
|
||||
|
||||
|
||||
|
||||
namespace ProjectCompRepair
|
||||
{
|
||||
@ -23,13 +30,29 @@ namespace ProjectCompRepair
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container.RegisterType<IAccessoriesRepository, AccessoriesRepository>();
|
||||
container.RegisterType<IMasterRepository, MasterRepository>();
|
||||
container.RegisterType<IOrderRepository, OrderRepository>();
|
||||
container.RegisterType<IServiceRepository, ServiceRepository>();
|
||||
|
||||
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||
|
||||
container.RegisterType<IAccessoriesRepository, AccessoriesRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IMasterRepository, MasterRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IOrderRepository, OrderRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IServiceRepository, ServiceRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IConnectionString, ConnectionString >(new TransientLifetimeManager());
|
||||
|
||||
|
||||
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,8 +9,19 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Npgsql" Version="8.0.5" />
|
||||
<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>
|
||||
|
@ -0,0 +1,19 @@
|
||||
using ProjectCompRepair.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCompRepair.Repositories;
|
||||
|
||||
public interface IAccessoriesOrder
|
||||
{
|
||||
void CreateAccessoriesOrder(AccessoiresOrder accessoriesOrder);
|
||||
|
||||
void DeleteAccessoriesOrder(int id);
|
||||
|
||||
IEnumerable<AccessoiresOrder> ReadAccessoiresOrder(int? Id = 0, int? orderId = 0, int? count = 0);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCompRepair.Repositories;
|
||||
|
||||
public interface IConnectionString
|
||||
{
|
||||
public string ConnectionString {get;}
|
||||
|
||||
}
|
@ -17,8 +17,6 @@ public interface IOrderRepository
|
||||
|
||||
void CreateOrder(Order order);
|
||||
|
||||
void UpdateOrder(Order order);
|
||||
|
||||
void DeleteOrder(int id);
|
||||
}
|
||||
|
||||
|
@ -4,33 +4,139 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using System.Data.SqlClient;
|
||||
using Dapper;
|
||||
using Npgsql;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ProjectCompRepair.Repositories.Implemantations;
|
||||
|
||||
public class AccessoriesRepository : IAccessoriesRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<AccessoriesRepository> _logger;
|
||||
|
||||
public AccessoriesRepository(IConnectionString connectionString, ILogger<AccessoriesRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateAccessories(Accessories accessories)
|
||||
{
|
||||
|
||||
}
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект : {json}", JsonConvert.SerializeObject(accessories));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
public void DeleteAccessories(int id)
|
||||
{
|
||||
|
||||
var queryInsert = @"
|
||||
INSERT INTO Accessories (AccessoriesType, Count, Price)
|
||||
VALUES (@AccessoriesType, @Count, @Price)";
|
||||
connection.Execute(queryInsert, accessories);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Accessories> ReadAccessories()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public Accessories ReadAccessoriesById(int id)
|
||||
{
|
||||
return Accessories.CreateEntity(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public void UpdateAccessories(Accessories accessories)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект : {json}", JsonConvert.SerializeObject(accessories));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryUpdate = @"UPDATE Accessories
|
||||
SET
|
||||
AccessoriesType = @AccessoriesType,
|
||||
Count = @Count,
|
||||
Price = @Price
|
||||
WHERE ID = @Id;";
|
||||
connection.Execute(queryUpdate, accessories);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void DeleteAccessories(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект : {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryDelete = @"
|
||||
DELETE FROM Accessories
|
||||
WHERE ID = @id
|
||||
"
|
||||
;
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public Accessories ReadAccessoriesById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект : {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelect = @"
|
||||
SELECT * FROM Accessories
|
||||
WHERE ID = @id
|
||||
";
|
||||
var accessories = connection.QueryFirst<Accessories>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект {json}", JsonConvert.SerializeObject(accessories));
|
||||
return accessories;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public IEnumerable<Accessories> ReadAccessories()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelect = @"SELECT * FROM Accessories";
|
||||
var accessories = connection.Query<Accessories>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты : {json}", JsonConvert.SerializeObject(accessories));
|
||||
return accessories;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCompRepair.Repositories.Implemantations;
|
||||
public class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "host=localhost;port=5432;username=postgres;password=123;Database=otp;";
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
using ProjectCompRepair.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectCompRepair.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,28 +14,123 @@ namespace ProjectCompRepair.Repositories.Implemantations;
|
||||
|
||||
public class MasterRepository : IMasterRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<AccessoriesRepository> _logger;
|
||||
|
||||
public MasterRepository(IConnectionString connectionString, ILogger<AccessoriesRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateMaster(Master master)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект : {json}", JsonConvert.SerializeObject(master));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryInsert = @"
|
||||
INSERT INTO Master (Name)
|
||||
VALUES (@Name)";
|
||||
connection.Execute(queryInsert, 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);
|
||||
connection.Open();
|
||||
|
||||
var queryDelete = @"
|
||||
DELETE FROM Master
|
||||
WHERE ID = @id
|
||||
"
|
||||
;
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Master> ReadMaster()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public Master ReadMasterById(int id)
|
||||
{
|
||||
return Master.CreateEntity(0, string.Empty);
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект : {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
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 void UpdateMaster(Master master)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект : {json}", JsonConvert.SerializeObject(master));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryUpdate = @"UPDATE Master
|
||||
SET
|
||||
Name = @Name
|
||||
WHERE ID = @Id;";
|
||||
connection.Execute(queryUpdate, master);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,148 @@
|
||||
using ProjectCompRepair.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectCompRepair.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCompRepair.Repositories.Implemantations;
|
||||
namespace ProjectCompRepair.Repositories.Implemantations;
|
||||
|
||||
public class OrderRepository : IOrderRepository
|
||||
{
|
||||
public class OrderRepository : IOrderRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<AccessoriesRepository> _logger;
|
||||
|
||||
public OrderRepository(IConnectionString connectionString, ILogger<AccessoriesRepository> 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();
|
||||
|
||||
public void DeleteOrder(int id)
|
||||
{
|
||||
|
||||
}
|
||||
var queryInsert = @"
|
||||
INSERT INTO Orderl (Name, Coment, Date, MasterId)
|
||||
VALUES (@Name, @Coment, @Date, @MasterId);
|
||||
SELECT MAX(ID) FROM Orderl";
|
||||
|
||||
public IEnumerable<Order> ReadOrder()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var orderId = connection.QueryFirst<int>(queryInsert, order, transaction);
|
||||
|
||||
public Order ReadOrderById(int id)
|
||||
{
|
||||
return Order.CreateElement(0, string.Empty, string.Empty, 0);
|
||||
}
|
||||
var querySubInsertAccessories = @"
|
||||
INSERT INTO AccessoriesOrder (OrderId, Count)
|
||||
VALUES (@OrderId, @Count)";
|
||||
|
||||
public void UpdateOrder(Order order)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
foreach (var elem in order.AccessoiresOrders)
|
||||
{
|
||||
connection.Execute(querySubInsertAccessories, new
|
||||
{
|
||||
OrderId = orderId,
|
||||
elem.Count
|
||||
}, transaction);
|
||||
}
|
||||
|
||||
}
|
||||
var querySubInsertServices = @"
|
||||
INSERT INTO ServicesOrder (OrderId, Count)
|
||||
VALUES (@OrderId, @Count)";
|
||||
|
||||
foreach (var elem in order.ServicesOrders)
|
||||
{
|
||||
connection.Execute(querySubInsertServices, new
|
||||
{
|
||||
OrderId = orderId,
|
||||
elem.Count
|
||||
}, transaction);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteOrder(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект : {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryDelete = @"
|
||||
DELETE FROM Orderl
|
||||
WHERE ID = @id
|
||||
"
|
||||
;
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public Order ReadOrderById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект : {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelect = @"
|
||||
SELECT * FROM Orderl
|
||||
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> ReadOrder()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelect = @"SELECT * FROM Orderl";
|
||||
var order = connection.Query<Order>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты : {json}", JsonConvert.SerializeObject(order));
|
||||
return order;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,8 @@
|
||||
using ProjectCompRepair.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectCompRepair.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,28 +13,124 @@ namespace ProjectCompRepair.Repositories.Implemantations;
|
||||
|
||||
public class ServiceRepository : IServiceRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<AccessoriesRepository> _logger;
|
||||
|
||||
public ServiceRepository(IConnectionString connectionString, ILogger<AccessoriesRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateService(Service service)
|
||||
{
|
||||
|
||||
}
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект : {json}", JsonConvert.SerializeObject(service));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryInsert = @"
|
||||
INSERT INTO Service (ServiceType, Price)
|
||||
VALUES (@ServiceType, @Price)";
|
||||
connection.Execute(queryInsert, service);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateService(Service service)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект : {json}", JsonConvert.SerializeObject(service));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryUpdate = @"UPDATE Service
|
||||
SET
|
||||
ServiceType = @ServiceType,
|
||||
Price = @Price
|
||||
WHERE ID = @Id;";
|
||||
connection.Execute(queryUpdate, service);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void DeleteService(int id)
|
||||
{
|
||||
|
||||
}
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект : {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
public IEnumerable<Service> ReadService()
|
||||
{
|
||||
return [];
|
||||
var queryDelete = @"
|
||||
DELETE FROM Service
|
||||
WHERE ID = @id
|
||||
"
|
||||
;
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Service ReadServiceById(int id)
|
||||
{
|
||||
return Service.CreateEntity(0, Entities.Enums.ServiceType.None, 0);
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект : {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelect = @"
|
||||
SELECT * FROM Service
|
||||
WHERE ID = @id
|
||||
";
|
||||
var service = connection.QueryFirst<Service>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект {json}", JsonConvert.SerializeObject(service));
|
||||
return service;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public IEnumerable<Service> ReadService()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelect = @"SELECT * FROM Service";
|
||||
var service = connection.Query<Service>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты : {json}", JsonConvert.SerializeObject(service));
|
||||
return service;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateService(Service service)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user
Много пустых строк