Исправленная вторая лабораторная работа (гол)(окончательно)
This commit is contained in:
parent
f64a40bcd7
commit
69d4f156d5
@ -9,13 +9,13 @@ namespace ProjectTourismCompany.Entities;
|
|||||||
public class Check
|
public class Check
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public string Title { get; private set; } = string.Empty;
|
//public string TripTitle { get; private set; } = string.Empty;
|
||||||
public DateTime PurchaseDate { get; private set; }
|
public DateTime PurchaseDate { get; private set; }
|
||||||
public int Price { get; private set; }
|
public int Price { get; private set; }
|
||||||
public int TripId { get; private set; }
|
public int TripId { get; private set; }
|
||||||
public int ClientId { get; private set; }
|
public int ClientId { get; private set; }
|
||||||
public static Check CreateCheck(int id, DateTime purchaseDate, int price, int tripId, int clientId)
|
public static Check CreateCheck(int id, DateTime purchaseDate, int price, int tripId, int clientId)//string triptitle,
|
||||||
{
|
{
|
||||||
return new Check() { Id = id, PurchaseDate = purchaseDate, Price = price, TripId = tripId, ClientId = clientId };
|
return new Check() { Id = id, PurchaseDate = purchaseDate, Price = price, TripId = tripId, ClientId = clientId };//TripTitle = triptitle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,15 +10,15 @@ public class CompanyTrip
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int CompanyId { get; private set; }
|
public int CompanyId { get; private set; }
|
||||||
public int TripId { get; private set; }
|
//public int TripId { get; private set; }
|
||||||
public int AdditionalPrice { get; private set; }
|
public int AdditionalPrice { get; private set; }
|
||||||
public static CompanyTrip CreateCompanyTrip(int id, int companyId, int tripId, int additionalPrice)
|
public static CompanyTrip CreateCompanyTrip(int id, int companyId , int additionalPrice)//int tripId,
|
||||||
{
|
{
|
||||||
return new CompanyTrip()
|
return new CompanyTrip()
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
CompanyId = companyId,
|
CompanyId = companyId,
|
||||||
TripId = tripId,
|
//TripId = tripId,
|
||||||
AdditionalPrice = additionalPrice
|
AdditionalPrice = additionalPrice
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ public class Trip
|
|||||||
public DateTime EndDate { get; private set;}
|
public DateTime EndDate { get; private set;}
|
||||||
public string StartCity { get; private set; }=string.Empty;
|
public string StartCity { get; private set; }=string.Empty;
|
||||||
public string EndCity { get; private set;} =string.Empty;
|
public string EndCity { get; private set;} =string.Empty;
|
||||||
public int CompanyId { get; private set; }
|
|
||||||
public TravelType TravelType { get; private set; }
|
public TravelType TravelType { get; private set; }
|
||||||
|
|
||||||
public IEnumerable<CompanyTrip> CompanyTrip
|
public IEnumerable<CompanyTrip> CompanyTrip
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
label2 = new Label();
|
label2 = new Label();
|
||||||
label4 = new Label();
|
label4 = new Label();
|
||||||
comboBoxClient = new ComboBox();
|
comboBoxClient = new ComboBox();
|
||||||
comboBoxTrip = new ComboBox();
|
comboBoxTripId = new ComboBox();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -125,21 +125,21 @@
|
|||||||
comboBoxClient.Size = new Size(217, 28);
|
comboBoxClient.Size = new Size(217, 28);
|
||||||
comboBoxClient.TabIndex = 41;
|
comboBoxClient.TabIndex = 41;
|
||||||
//
|
//
|
||||||
// comboBoxTrip
|
// comboBoxTripId
|
||||||
//
|
//
|
||||||
comboBoxTrip.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxTripId.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxTrip.FormattingEnabled = true;
|
comboBoxTripId.FormattingEnabled = true;
|
||||||
comboBoxTrip.Location = new Point(281, 155);
|
comboBoxTripId.Location = new Point(281, 155);
|
||||||
comboBoxTrip.Name = "comboBoxTrip";
|
comboBoxTripId.Name = "comboBoxTripId";
|
||||||
comboBoxTrip.Size = new Size(217, 28);
|
comboBoxTripId.Size = new Size(217, 28);
|
||||||
comboBoxTrip.TabIndex = 42;
|
comboBoxTripId.TabIndex = 42;
|
||||||
//
|
//
|
||||||
// FormCheck
|
// FormCheck
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(513, 272);
|
ClientSize = new Size(516, 281);
|
||||||
Controls.Add(comboBoxTrip);
|
Controls.Add(comboBoxTripId);
|
||||||
Controls.Add(comboBoxClient);
|
Controls.Add(comboBoxClient);
|
||||||
Controls.Add(label4);
|
Controls.Add(label4);
|
||||||
Controls.Add(label2);
|
Controls.Add(label2);
|
||||||
@ -168,6 +168,6 @@
|
|||||||
private Label label2;
|
private Label label2;
|
||||||
private Label label4;
|
private Label label4;
|
||||||
private ComboBox comboBoxClient;
|
private ComboBox comboBoxClient;
|
||||||
private ComboBox comboBoxTrip;
|
private ComboBox comboBoxTripId;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,11 +32,6 @@ public partial class FormCheck : Form
|
|||||||
}
|
}
|
||||||
dateTimePickerPurchaseDate.Value = check.PurchaseDate;
|
dateTimePickerPurchaseDate.Value = check.PurchaseDate;
|
||||||
numericUpDownPrice.Value = check.Price;
|
numericUpDownPrice.Value = check.Price;
|
||||||
|
|
||||||
comboBoxTrip.SelectedItem = check.Title;
|
|
||||||
|
|
||||||
|
|
||||||
comboBoxTrip.SelectedItem = check.TripId;
|
|
||||||
_checkId = value;
|
_checkId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -54,24 +49,25 @@ public partial class FormCheck : Form
|
|||||||
comboBoxClient.DataSource = clientRepository.ReadClients();
|
comboBoxClient.DataSource = clientRepository.ReadClients();
|
||||||
comboBoxClient.DisplayMember = "Name";
|
comboBoxClient.DisplayMember = "Name";
|
||||||
comboBoxClient.ValueMember = "Id";
|
comboBoxClient.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxTrip.DisplayMember = "Title";
|
comboBoxTripId.DataSource = tripRepository.ReadTrips();
|
||||||
comboBoxTrip.ValueMember = "Id";
|
comboBoxTripId.DisplayMember = "Title";
|
||||||
comboBoxTrip.DataSource = tripRepository.ReadTrips();
|
comboBoxTripId.ValueMember = "Id";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private void buttonSave_Click(object sender, EventArgs e)
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (comboBoxTrip.SelectedIndex < 0 ||
|
if (comboBoxTripId.SelectedIndex < 0 ||
|
||||||
comboBoxClient.SelectedIndex < 0)
|
comboBoxClient.SelectedIndex < 0)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
_checkRepository.CreateCheck(Check.CreateCheck(_checkId, dateTimePickerPurchaseDate.Value,
|
_checkRepository.CreateCheck(Check.CreateCheck(_checkId , dateTimePickerPurchaseDate.Value,
|
||||||
(int)numericUpDownPrice.Value, (int)comboBoxTrip.SelectedIndex!,
|
(int)numericUpDownPrice.Value, (int)comboBoxTripId.SelectedValue!,
|
||||||
(int)comboBoxClient.SelectedIndex!));
|
(int)comboBoxClient.SelectedValue!));
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
dataGridViewChecks.RowHeadersVisible = false;
|
dataGridViewChecks.RowHeadersVisible = false;
|
||||||
dataGridViewChecks.RowHeadersWidth = 51;
|
dataGridViewChecks.RowHeadersWidth = 51;
|
||||||
dataGridViewChecks.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridViewChecks.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridViewChecks.Size = new Size(800, 450);
|
dataGridViewChecks.Size = new Size(643, 450);
|
||||||
dataGridViewChecks.TabIndex = 0;
|
dataGridViewChecks.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// panel1
|
// panel1
|
||||||
@ -92,8 +92,8 @@
|
|||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
Controls.Add(panel1);
|
|
||||||
Controls.Add(dataGridViewChecks);
|
Controls.Add(dataGridViewChecks);
|
||||||
|
Controls.Add(panel1);
|
||||||
Name = "FormChecks";
|
Name = "FormChecks";
|
||||||
Text = "Чеки";
|
Text = "Чеки";
|
||||||
Load += FormChecks_Load;
|
Load += FormChecks_Load;
|
||||||
|
@ -33,6 +33,7 @@ public partial class FormCompany : Form
|
|||||||
|
|
||||||
textBoxName.Text = client.Name;
|
textBoxName.Text = client.Name;
|
||||||
comboBoxCountry.SelectedItem = client.CountryId;
|
comboBoxCountry.SelectedItem = client.CountryId;
|
||||||
|
comboBoxCountry.SelectedValue = client.CountryId;
|
||||||
_companyId = value;
|
_companyId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -57,6 +58,7 @@ public partial class FormCompany : Form
|
|||||||
comboBoxCountry.DataSource = countryRepository.ReadCountries();
|
comboBoxCountry.DataSource = countryRepository.ReadCountries();
|
||||||
comboBoxCountry.DisplayMember = "CountryName";
|
comboBoxCountry.DisplayMember = "CountryName";
|
||||||
comboBoxCountry.ValueMember = "Id";
|
comboBoxCountry.ValueMember = "Id";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -64,11 +66,18 @@ public partial class FormCompany : Form
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
if (string.IsNullOrWhiteSpace(textBoxName.Text))
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
if (_companyId.HasValue)
|
||||||
|
{
|
||||||
|
_companyRepository.UpdateCompany(CreateCompany(_companyId.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_companyRepository.CreateCompany(CreateCompany(0));
|
||||||
}
|
}
|
||||||
_companyRepository.CreateCompany(Company.CreateCompany(0, textBoxName.Text, (int)comboBoxCountry.SelectedItem!));
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -76,8 +85,15 @@ public partial class FormCompany : Form
|
|||||||
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) =>
|
private void ButtonCancel_Click(object sender, EventArgs e) =>
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private Company CreateCompany(int id)
|
||||||
|
{
|
||||||
|
return Company.CreateCompany(id, textBoxName.Text, (int)comboBoxCountry.SelectedValue!);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,6 @@
|
|||||||
dataGridView1.Location = new Point(3, 23);
|
dataGridView1.Location = new Point(3, 23);
|
||||||
dataGridView1.MultiSelect = false;
|
dataGridView1.MultiSelect = false;
|
||||||
dataGridView1.Name = "dataGridView1";
|
dataGridView1.Name = "dataGridView1";
|
||||||
dataGridView1.ReadOnly = true;
|
|
||||||
dataGridView1.RowHeadersVisible = false;
|
dataGridView1.RowHeadersVisible = false;
|
||||||
dataGridView1.RowHeadersWidth = 51;
|
dataGridView1.RowHeadersWidth = 51;
|
||||||
dataGridView1.Size = new Size(426, 450);
|
dataGridView1.Size = new Size(426, 450);
|
||||||
@ -248,14 +247,12 @@
|
|||||||
columnCompanyName.HeaderText = "Название компании";
|
columnCompanyName.HeaderText = "Название компании";
|
||||||
columnCompanyName.MinimumWidth = 6;
|
columnCompanyName.MinimumWidth = 6;
|
||||||
columnCompanyName.Name = "columnCompanyName";
|
columnCompanyName.Name = "columnCompanyName";
|
||||||
columnCompanyName.ReadOnly = true;
|
|
||||||
//
|
//
|
||||||
// ColumnAdditionalPrice
|
// ColumnAdditionalPrice
|
||||||
//
|
//
|
||||||
ColumnAdditionalPrice.HeaderText = "Добавочная стоимость";
|
ColumnAdditionalPrice.HeaderText = "Добавочная стоимость";
|
||||||
ColumnAdditionalPrice.MinimumWidth = 6;
|
ColumnAdditionalPrice.MinimumWidth = 6;
|
||||||
ColumnAdditionalPrice.Name = "ColumnAdditionalPrice";
|
ColumnAdditionalPrice.Name = "ColumnAdditionalPrice";
|
||||||
ColumnAdditionalPrice.ReadOnly = true;
|
|
||||||
ColumnAdditionalPrice.Resizable = DataGridViewTriState.True;
|
ColumnAdditionalPrice.Resizable = DataGridViewTriState.True;
|
||||||
ColumnAdditionalPrice.SortMode = DataGridViewColumnSortMode.NotSortable;
|
ColumnAdditionalPrice.SortMode = DataGridViewColumnSortMode.NotSortable;
|
||||||
//
|
//
|
||||||
|
@ -74,19 +74,11 @@ Enum.GetValues(typeof(TravelType)))
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(textBoxStartCity.Text) ||
|
if (string.IsNullOrWhiteSpace(textBoxStartCity.Text) ||
|
||||||
string.IsNullOrWhiteSpace(textBoxEndCity.Text) || dataGridView1.RowCount < 1)
|
string.IsNullOrWhiteSpace(textBoxEndCity.Text) || dataGridView1.RowCount < 1 || dateTimePickerStartDate.Value > dateTimePickerEndDate.Value)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные или некорректно заполненные поля");
|
||||||
}
|
|
||||||
|
|
||||||
if (_tripId.HasValue)
|
|
||||||
{
|
|
||||||
_tripRepository.CreateTrip(CreateTrip(_tripId.Value));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_tripRepository.CreateTrip(CreateTrip(0));
|
|
||||||
}
|
}
|
||||||
|
_tripRepository.CreateTrip(CreateTrip(0));
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
@ -122,7 +114,7 @@ Enum.GetValues(typeof(TravelType)))
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
list.Add(CompanyTrip.CreateCompanyTrip(0, 0,
|
list.Add(CompanyTrip.CreateCompanyTrip(0,
|
||||||
Convert.ToInt32(row.Cells["ColumnCompanyName"].Value),
|
Convert.ToInt32(row.Cells["ColumnCompanyName"].Value),
|
||||||
Convert.ToInt32(row.Cells["ColumnAdditionalPrice"].Value)));
|
Convert.ToInt32(row.Cells["ColumnAdditionalPrice"].Value)));
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
dataGridView1.MultiSelect = false;
|
dataGridView1.MultiSelect = false;
|
||||||
dataGridView1.Name = "dataGridView1";
|
dataGridView1.Name = "dataGridView1";
|
||||||
dataGridView1.ReadOnly = true;
|
dataGridView1.ReadOnly = true;
|
||||||
|
dataGridView1.RowHeadersVisible = false;
|
||||||
dataGridView1.RowHeadersWidth = 51;
|
dataGridView1.RowHeadersWidth = 51;
|
||||||
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridView1.Size = new Size(645, 450);
|
dataGridView1.Size = new Size(645, 450);
|
||||||
|
@ -33,8 +33,8 @@ internal class CheckRepository : ICheckRepository
|
|||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Receipt (Title, PurchaseDate, Price, TripId, ClientId)
|
INSERT INTO Receipt (PurchaseDate, Price, TripId, ClientId)
|
||||||
VALUES (@Title, @PurchaseDate, @Price, @TripId, @ClientId)";
|
VALUES (@PurchaseDate, @Price, @TripId, @ClientId)";
|
||||||
connection.Execute(queryInsert, check);
|
connection.Execute(queryInsert, check);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -9,6 +9,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Unity;
|
||||||
|
|
||||||
namespace ProjectTourismCompany.Repositories.Implementations;
|
namespace ProjectTourismCompany.Repositories.Implementations;
|
||||||
|
|
||||||
@ -33,35 +34,18 @@ internal class CompanyRepository : ICompanyRepository
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
NpgsqlConnection(_connectionString.ConnectionString);
|
|
||||||
connection.Open();
|
|
||||||
using var transaction = connection.BeginTransaction();
|
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Company (Name, CountryId)
|
INSERT INTO Company (Name, CountryId)
|
||||||
VALUES (@Name, @CountryId);
|
VALUES (@Name, @CountryId)";
|
||||||
SELECT MAX(Id) FROM Company";
|
connection.Execute(queryInsert, company);
|
||||||
var companyId =
|
|
||||||
connection.QueryFirst<int>(queryInsert, company, transaction);
|
|
||||||
var querySubInsert = @"
|
|
||||||
INSERT INTO CompanyTrip (CompanyId, TripId, AdditionalPrice)
|
|
||||||
VALUES (@CompanyId, @TripId, @AdditionalPrice)";
|
|
||||||
foreach (var elem in company.CompanyTrip)
|
|
||||||
{
|
|
||||||
connection.Execute(querySubInsert, new
|
|
||||||
{
|
|
||||||
companyId,
|
|
||||||
elem.TripId,
|
|
||||||
elem.AdditionalPrice
|
|
||||||
}, transaction);
|
|
||||||
}
|
|
||||||
transaction.Commit();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteCompany(int id)
|
public void DeleteCompany(int id)
|
||||||
|
@ -27,20 +27,38 @@ internal class TripRepository : ITripRepository
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Добавление объекта");
|
_logger.LogInformation("Добавление объекта");
|
||||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(trip));
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(trip));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new
|
||||||
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Trip (Title, Price, HumanCapacity, StartDate, EndDate, StartCity, EndCity, CompanyId, TravelType)
|
INSERT INTO Trip (Title, Price, HumanCapacity, StartDate, EndDate, StartCity, EndCity, TravelType)
|
||||||
VALUES (@Title, @Price, @HumanCapacity, @StartDate, @EndDate, @StartCity, @EndCity, @CompanyId, @TravelType)";
|
VALUES (@Title, @Price, @HumanCapacity, @StartDate, @EndDate, @StartCity, @EndCity, @TravelType);
|
||||||
connection.Execute(queryInsert, trip);
|
SELECT MAX(Id) FROM Trip";
|
||||||
|
var companyTripId =
|
||||||
|
connection.QueryFirst<int>(queryInsert, trip, transaction);
|
||||||
|
var querySubInsert = @"
|
||||||
|
INSERT INTO CompanyTrip (CompanyId, AdditionalPrice)
|
||||||
|
VALUES (@CompanyId, @AdditionalPrice)";
|
||||||
|
foreach (var elem in trip.CompanyTrip)
|
||||||
|
{
|
||||||
|
connection.Execute(querySubInsert, new
|
||||||
|
{
|
||||||
|
companyTripId,
|
||||||
|
elem.CompanyId,
|
||||||
|
elem.AdditionalPrice
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Trip ReadTripById(int id)
|
public Trip ReadTripById(int id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user