Заставляем бд рабоатть с прилоением, все еще...
This commit is contained in:
parent
6aa29f1308
commit
34a69d1793
@ -9,17 +9,15 @@ namespace ProjectTourAgency.Enities;
|
||||
public class Route
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int TourId { get; private set; }
|
||||
public string Destination { get; private set; } = string.Empty;
|
||||
public string Departure { get; private set; } = string.Empty;
|
||||
public int Duration { get; private set; }
|
||||
public static Route CreateEntity(int id, int TourId, string destination,
|
||||
public static Route CreateEntity(int id, string destination,
|
||||
string departure, int duration)
|
||||
{
|
||||
return new Route
|
||||
{
|
||||
Id = id,
|
||||
TourId = TourId,
|
||||
Destination = destination,
|
||||
Departure = departure,
|
||||
Duration = duration
|
||||
|
@ -35,7 +35,7 @@ namespace ProjectTourAgency.Forms
|
||||
textBoxNumber.Text = client.PhoneNumber;
|
||||
textBoxMoney.Text = client.Money.ToString();
|
||||
dateTimePickerDate.Value = client.BirthDate;
|
||||
|
||||
_clientId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -70,7 +70,7 @@ namespace ProjectTourAgency.Forms
|
||||
}
|
||||
else
|
||||
{
|
||||
_clientRepository.CreateClient(CreateClient(_clientId.Value));
|
||||
_clientRepository.CreateClient(CreateClient(0));
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using ProjectEmployeeAgency.Repositories;
|
||||
using ProjectRouteAgency.Repositories;
|
||||
using ProjectTourAgency.Enities;
|
||||
using ProjectTourAgency.Enities.Enums;
|
||||
using ProjectTourAgency.Implementations;
|
||||
using ProjectTourAgency.Repositories;
|
||||
using System;
|
||||
@ -34,6 +35,7 @@ namespace ProjectTourAgency.Forms
|
||||
}
|
||||
textBoxName.Text = employee.FullName;
|
||||
comboBoxJob.SelectedItem = employee.EmployeeJob;
|
||||
_employeeId = value;
|
||||
|
||||
|
||||
}
|
||||
@ -50,6 +52,7 @@ namespace ProjectTourAgency.Forms
|
||||
InitializeComponent();
|
||||
_employeeRepository = employeeRepository ??
|
||||
throw new ArgumentNullException(nameof(employeeRepository));
|
||||
comboBoxJob.DataSource = Enum.GetValues(typeof(EmpoyeeJob));
|
||||
|
||||
}
|
||||
|
||||
@ -69,7 +72,7 @@ namespace ProjectTourAgency.Forms
|
||||
}
|
||||
else
|
||||
{
|
||||
_employeeRepository.CreateEmployee(CreateEmployee(_employeeId.Value));
|
||||
_employeeRepository.CreateEmployee(CreateEmployee(0));
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ namespace ProjectTourAgency.Forms
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormClient>().ShowDialog();
|
||||
_container.Resolve<FormEmployee>().ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -32,76 +32,72 @@
|
||||
labelDestination = new Label();
|
||||
labelDeparture = new Label();
|
||||
textBoxDuration = new TextBox();
|
||||
labelTourId = new Label();
|
||||
textBoxDeparture = new TextBox();
|
||||
labelDuration = new Label();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
comboBoxTourId = new ComboBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBoxDestination
|
||||
//
|
||||
textBoxDestination.Location = new Point(144, 32);
|
||||
textBoxDestination.Location = new Point(206, 53);
|
||||
textBoxDestination.Margin = new Padding(4, 5, 4, 5);
|
||||
textBoxDestination.Name = "textBoxDestination";
|
||||
textBoxDestination.Size = new Size(226, 23);
|
||||
textBoxDestination.Size = new Size(321, 31);
|
||||
textBoxDestination.TabIndex = 4;
|
||||
//
|
||||
// labelDestination
|
||||
//
|
||||
labelDestination.AutoSize = true;
|
||||
labelDestination.Location = new Point(38, 32);
|
||||
labelDestination.Location = new Point(15, 53);
|
||||
labelDestination.Margin = new Padding(4, 0, 4, 0);
|
||||
labelDestination.Name = "labelDestination";
|
||||
labelDestination.Size = new Size(100, 15);
|
||||
labelDestination.Size = new Size(148, 25);
|
||||
labelDestination.TabIndex = 3;
|
||||
labelDestination.Text = "Место прибытия";
|
||||
//
|
||||
// labelDeparture
|
||||
//
|
||||
labelDeparture.AutoSize = true;
|
||||
labelDeparture.Location = new Point(38, 78);
|
||||
labelDeparture.Location = new Point(15, 131);
|
||||
labelDeparture.Margin = new Padding(4, 0, 4, 0);
|
||||
labelDeparture.Name = "labelDeparture";
|
||||
labelDeparture.Size = new Size(91, 15);
|
||||
labelDeparture.Size = new Size(135, 25);
|
||||
labelDeparture.TabIndex = 5;
|
||||
labelDeparture.Text = "Место отбытия";
|
||||
//
|
||||
// textBoxDuration
|
||||
//
|
||||
textBoxDuration.Location = new Point(144, 114);
|
||||
textBoxDuration.Location = new Point(206, 190);
|
||||
textBoxDuration.Margin = new Padding(4, 5, 4, 5);
|
||||
textBoxDuration.Name = "textBoxDuration";
|
||||
textBoxDuration.Size = new Size(226, 23);
|
||||
textBoxDuration.Size = new Size(321, 31);
|
||||
textBoxDuration.TabIndex = 7;
|
||||
//
|
||||
// labelTourId
|
||||
//
|
||||
labelTourId.AutoSize = true;
|
||||
labelTourId.Location = new Point(38, 163);
|
||||
labelTourId.Name = "labelTourId";
|
||||
labelTourId.Size = new Size(94, 15);
|
||||
labelTourId.TabIndex = 6;
|
||||
labelTourId.Text = "Стоимость тура";
|
||||
//
|
||||
// textBoxDeparture
|
||||
//
|
||||
textBoxDeparture.Location = new Point(144, 75);
|
||||
textBoxDeparture.Location = new Point(206, 125);
|
||||
textBoxDeparture.Margin = new Padding(4, 5, 4, 5);
|
||||
textBoxDeparture.Name = "textBoxDeparture";
|
||||
textBoxDeparture.Size = new Size(226, 23);
|
||||
textBoxDeparture.Size = new Size(321, 31);
|
||||
textBoxDeparture.TabIndex = 8;
|
||||
//
|
||||
// labelDuration
|
||||
//
|
||||
labelDuration.AutoSize = true;
|
||||
labelDuration.Location = new Point(45, 117);
|
||||
labelDuration.Location = new Point(15, 193);
|
||||
labelDuration.Margin = new Padding(4, 0, 4, 0);
|
||||
labelDuration.Name = "labelDuration";
|
||||
labelDuration.Size = new Size(84, 15);
|
||||
labelDuration.Size = new Size(179, 25);
|
||||
labelDuration.TabIndex = 10;
|
||||
labelDuration.Text = "Дата отбытия";
|
||||
labelDuration.Text = "Продолжительность";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(63, 251);
|
||||
buttonSave.Location = new Point(87, 285);
|
||||
buttonSave.Margin = new Padding(4, 5, 4, 5);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(75, 23);
|
||||
buttonSave.Size = new Size(107, 38);
|
||||
buttonSave.TabIndex = 12;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
@ -109,40 +105,32 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(256, 251);
|
||||
buttonCancel.Location = new Point(363, 285);
|
||||
buttonCancel.Margin = new Padding(4, 5, 4, 5);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(75, 23);
|
||||
buttonCancel.Size = new Size(107, 38);
|
||||
buttonCancel.TabIndex = 13;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// comboBoxTourId
|
||||
//
|
||||
comboBoxTourId.FormattingEnabled = true;
|
||||
comboBoxTourId.Location = new Point(144, 163);
|
||||
comboBoxTourId.Name = "comboBoxTourId";
|
||||
comboBoxTourId.Size = new Size(226, 23);
|
||||
comboBoxTourId.TabIndex = 14;
|
||||
//
|
||||
// FormRoute
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(414, 284);
|
||||
Controls.Add(comboBoxTourId);
|
||||
ClientSize = new Size(591, 337);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(labelDuration);
|
||||
Controls.Add(textBoxDeparture);
|
||||
Controls.Add(textBoxDuration);
|
||||
Controls.Add(labelTourId);
|
||||
Controls.Add(labelDeparture);
|
||||
Controls.Add(textBoxDestination);
|
||||
Controls.Add(labelDestination);
|
||||
Margin = new Padding(4, 5, 4, 5);
|
||||
Name = "FormRoute";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Тур";
|
||||
Text = "Маршрут";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@ -153,13 +141,11 @@
|
||||
private Label labelDestination;
|
||||
private Label labelDeparture;
|
||||
private TextBox textBoxDuration;
|
||||
private Label labelTourId;
|
||||
private TextBox textBoxDeparture;
|
||||
private Label labelDate;
|
||||
private Label labelDuration;
|
||||
private TextBox textBoxPrice;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private ComboBox comboBoxTourId;
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ namespace ProjectTourAgency.Forms
|
||||
textBoxDestination.Text = route.Destination;
|
||||
textBoxDeparture.Text = route.Departure;
|
||||
textBoxDuration.Text = route.Duration.ToString();
|
||||
|
||||
_routeId = value;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
@ -49,9 +49,6 @@ namespace ProjectTourAgency.Forms
|
||||
InitializeComponent();
|
||||
_routeRepository = routeRepository ??
|
||||
throw new ArgumentNullException(nameof(routeRepository));
|
||||
comboBoxTourId.DataSource = tourRepository.ReadTours();
|
||||
comboBoxTourId.DisplayMember = "FullName";
|
||||
comboBoxTourId.ValueMember = "Id";
|
||||
|
||||
}
|
||||
|
||||
@ -61,7 +58,7 @@ namespace ProjectTourAgency.Forms
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxDestination.Text) ||
|
||||
string.IsNullOrWhiteSpace(textBoxDeparture.Text) || string.IsNullOrWhiteSpace(textBoxDuration.Text)
|
||||
|| string.IsNullOrWhiteSpace(textBoxPrice.Text) || string.IsNullOrWhiteSpace(dateTimePickerDepartureDate.Text))
|
||||
)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
@ -72,7 +69,7 @@ namespace ProjectTourAgency.Forms
|
||||
}
|
||||
else
|
||||
{
|
||||
_routeRepository.CreateRoute(CreateRoute(_routeId.Value));
|
||||
_routeRepository.CreateRoute(CreateRoute(0));
|
||||
}
|
||||
Close();
|
||||
}
|
||||
@ -85,7 +82,7 @@ namespace ProjectTourAgency.Forms
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
private Route CreateRoute(int id) => Route.CreateEntity(id, (int)comboBoxTourId.SelectedValue!, textBoxDestination.Text,
|
||||
private Route CreateRoute(int id) => Route.CreateEntity(id, textBoxDestination.Text,
|
||||
textBoxDeparture.Text, int.Parse(textBoxDuration.Text));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
|
@ -9,6 +9,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using System.Data.SqlClient;
|
||||
using Npgsql;
|
||||
using System.Transactions;
|
||||
|
||||
namespace ProjectTourAgency.Implementations;
|
||||
|
||||
@ -21,21 +23,38 @@ public class AddMoneyRepository : IAddMoneyRepository
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateAddMoney(AddMoney AddMoney)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {jspn}", JsonConvert.SerializeObject(AddMoney));
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
connection.Open(); // Открываем соединение
|
||||
|
||||
// Начинаем транзакцию
|
||||
using var transaction = connection.BeginTransaction();
|
||||
|
||||
var queryInsert = @"
|
||||
INSERT INTO AddMoneys (ClientId,Date,MoneyAmount)
|
||||
VALUES (@ClientId,@Date,@MoneyAmount)";
|
||||
connection.Execute(queryInsert, AddMoney);
|
||||
|
||||
var queryUpdate = @"
|
||||
UPDATE Clients
|
||||
SET Money = Money + @MoneyAmount
|
||||
WHERE Id = @ClientId
|
||||
";
|
||||
connection.Execute(queryUpdate, new { MoneyAmount = AddMoney.MoneyAmount, ClientId = AddMoney.ClientId }, transaction);
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
@ -47,7 +66,7 @@ VALUES (@ClientId,@Date,@MoneyAmount)";
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var queryDelete = @"
|
||||
DELETE FROM AddMoneys
|
||||
@ -68,10 +87,10 @@ WHERE Id = @Id";
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM AddMoneys
|
||||
WHERE [Id] = @Id";
|
||||
WHERE Id = @Id";
|
||||
var AddMoney = connection.QueryFirst<AddMoney>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(AddMoney));
|
||||
return AddMoney;
|
||||
@ -89,7 +108,7 @@ WHERE [Id] = @Id";
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM AddMoneys";
|
||||
var AddMoneys = connection.Query<AddMoney>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(AddMoneys));
|
||||
@ -109,7 +128,7 @@ WHERE [Id] = @Id";
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(AddMoney));
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE AddMoneys
|
||||
SET
|
||||
|
@ -9,6 +9,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.SqlClient;
|
||||
using Dapper;
|
||||
using Npgsql;
|
||||
|
||||
namespace ProjectTourAgency.Implementations;
|
||||
|
||||
@ -27,7 +28,7 @@ public class ClientRepository : IClientRepository
|
||||
_logger.LogDebug("Объект: {jspn}", JsonConvert.SerializeObject(client));
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Clients (FullName, BirthDate, PhoneNumber, Money)
|
||||
VALUES (@FullName, @BirthDate, @PhoneNumber, @Money)";
|
||||
@ -47,7 +48,7 @@ VALUES (@FullName, @BirthDate, @PhoneNumber, @Money)";
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var queryDelete = @"
|
||||
DELETE FROM CLients
|
||||
@ -68,10 +69,10 @@ WHERE Id = @Id";
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM CLients
|
||||
WHERE [Id] = @Id";
|
||||
WHERE Id = @Id";
|
||||
var client = connection.QueryFirst<Client>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(client));
|
||||
return client;
|
||||
@ -89,7 +90,7 @@ WHERE [Id] = @Id";
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM CLients";
|
||||
var clients = connection.Query<Client>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(clients));
|
||||
@ -109,7 +110,7 @@ WHERE [Id] = @Id";
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(client));
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE CLients
|
||||
SET
|
||||
|
@ -9,5 +9,5 @@ namespace ProjectTourAgency.Implementations;
|
||||
|
||||
public class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "Server=localHost;Port=...;Database=...;";
|
||||
string IConnectionString.ConnectionString => "Server=localHost;Port=5432;Database=otp;Username=postgres;Password=1488;Include Error Detail = True ";
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using Newtonsoft.Json;
|
||||
using Dapper;
|
||||
using ProjectEmployeeAgency.Repositories;
|
||||
using System.Data.SqlClient;
|
||||
using Npgsql;
|
||||
|
||||
namespace ProjectTourAgency.Implementations;
|
||||
|
||||
@ -23,7 +24,7 @@ public class EmployeeRepository : IEmployeeRepository
|
||||
_logger.LogDebug("Объект: {jspn}", JsonConvert.SerializeObject(Employee));
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Employees (FullName, EmployeeJob)
|
||||
VALUES (@FullName, @EmployeeJob)";
|
||||
@ -43,7 +44,7 @@ VALUES (@FullName, @EmployeeJob)";
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var queryDelete = @"
|
||||
DELETE FROM Employees
|
||||
@ -64,10 +65,10 @@ WHERE Id = @Id";
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Employees
|
||||
WHERE [Id] = @Id";
|
||||
WHERE Id = @Id";
|
||||
var Employee = connection.QueryFirst<Employee>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(Employee));
|
||||
return Employee;
|
||||
@ -85,7 +86,7 @@ WHERE [Id] = @Id";
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM Employees";
|
||||
var Employees = connection.Query<Employee>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(Employees));
|
||||
@ -105,7 +106,7 @@ WHERE [Id] = @Id";
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(Employee));
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Employees
|
||||
SET
|
||||
|
@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using System.Data.SqlClient;
|
||||
using ProjectRouteAgency.Repositories;
|
||||
using Npgsql;
|
||||
|
||||
namespace ProjectTourAgency.Implementations;
|
||||
|
||||
@ -28,10 +29,10 @@ public class RouteRepository : IRouteRepository
|
||||
_logger.LogDebug("Объект: {jspn}", JsonConvert.SerializeObject(Route));
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Routes (TourId, Destination, Departure, Duration)
|
||||
VALUES (@TourId, @Destination, @Departure, @Duration)";
|
||||
INSERT INTO Routes (Destination, Departure, Duration)
|
||||
VALUES (@Destination, @Departure, @Duration)";
|
||||
connection.Execute(queryInsert, Route);
|
||||
|
||||
}
|
||||
@ -48,7 +49,7 @@ VALUES (@TourId, @Destination, @Departure, @Duration)";
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
var queryDelete = @"
|
||||
DELETE FROM Routes
|
||||
@ -69,10 +70,10 @@ WHERE Id = @Id";
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Routes
|
||||
WHERE [Id] = @Id";
|
||||
WHERE Id = @Id";
|
||||
var Route = connection.QueryFirst<Route>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(Route));
|
||||
return Route;
|
||||
@ -90,7 +91,7 @@ WHERE [Id] = @Id";
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM Routes";
|
||||
var Routes = connection.Query<Route>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(Routes));
|
||||
@ -110,11 +111,10 @@ WHERE [Id] = @Id";
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(Route));
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Routes
|
||||
SET
|
||||
TourId = @TourId,
|
||||
Destination = @Destination,
|
||||
Departure = @Departure,
|
||||
Duration = @Duration
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectTourAgency.Enities;
|
||||
using ProjectTourAgency.Repositories;
|
||||
using System;
|
||||
@ -26,15 +27,16 @@ public class TourRepository : ITourRepository
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(tour));
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO Tour(EmployeeId, RouteId, DepartureDate, ClientTours)
|
||||
VALUES (@EmployeeId, @RouteId, @DepartureDate, @ClientTours)
|
||||
INSERT INTO Tour(EmployeeId, RouteId, DepartureDate)
|
||||
VALUES (@EmployeeId, @RouteId, @DepartureDate);
|
||||
SELECT MAX(Id) FROM Tour
|
||||
";
|
||||
var tourID = connection.QueryFirst<int>(queryInsert, tour, transaction);
|
||||
@ -43,7 +45,7 @@ INSERT INTO ClientTour(ClientId, TourId, Cost)
|
||||
VALUES (@ClientId, @TourId, @Cost)";
|
||||
foreach (var elem in tour.ClientTours)
|
||||
{
|
||||
connection.Execute(querySubInsert, new { tourID, elem.ClientId, elem.Cost });
|
||||
connection.Execute(querySubInsert, new { tourID, elem.ClientId, elem.Cost }, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
@ -60,7 +62,7 @@ VALUES (@ClientId, @TourId, @Cost)";
|
||||
_logger.LogDebug("Объекьт: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Tour
|
||||
WHERE Id = @id";
|
||||
@ -79,7 +81,7 @@ WHERE Id = @id";
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM Tour";
|
||||
var tour = connection.Query<Tour>(querySelect);
|
||||
_logger.LogDebug("Получение объектов {json}", JsonConvert.SerializeObject(tour));
|
||||
|
@ -14,6 +14,7 @@
|
||||
<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" />
|
||||
|
Loading…
Reference in New Issue
Block a user