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