лаба 2 готова
This commit is contained in:
parent
07835de7ef
commit
7110647bdd
@ -6,16 +6,16 @@ public class Bus
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string LicensePlate { get; private set; } = string.Empty;
|
||||
public string Licence_plate { get; private set; } = string.Empty;
|
||||
|
||||
public string Model { get; private set; } = string.Empty;
|
||||
|
||||
public static Bus CreateEntity(int id, string licensePlate, string model)
|
||||
public static Bus CreateEntity(int id, string licencePlate, string model)
|
||||
{
|
||||
return new Bus
|
||||
{
|
||||
Id = id,
|
||||
LicensePlate = licensePlate,
|
||||
Licence_plate = licencePlate,
|
||||
Model = model
|
||||
};
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ public class Employee
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string FirstName { get; private set; } = string.Empty;
|
||||
public string First_name { get; private set; } = string.Empty;
|
||||
|
||||
public string LastName { get; private set; } = string.Empty;
|
||||
public string Last_name { get; private set; } = string.Empty;
|
||||
|
||||
public EmployeePost Post { get; private set; }
|
||||
|
||||
@ -17,8 +17,8 @@ public class Employee
|
||||
return new Employee
|
||||
{
|
||||
Id = id,
|
||||
FirstName = first ?? string.Empty,
|
||||
LastName = last ?? string.Empty,
|
||||
First_name = first ?? string.Empty,
|
||||
Last_name = last ?? string.Empty,
|
||||
Post = post
|
||||
};
|
||||
}
|
||||
|
@ -8,11 +8,11 @@ public class GoToService
|
||||
|
||||
public DateTime Date { get; private set; }
|
||||
|
||||
public BrokenElements BrokenElements { get; private set; }
|
||||
public BrokenElements Broken_elements { get; private set; }
|
||||
|
||||
public int Price { get; private set; }
|
||||
|
||||
public int BusId { get; private set; }
|
||||
public int Bus_id { get; private set; }
|
||||
|
||||
public static GoToService CreateOperation(int id, BrokenElements brokenElements, int price, int busId)
|
||||
{
|
||||
@ -20,9 +20,9 @@ public class GoToService
|
||||
{
|
||||
Id = id,
|
||||
Date = DateTime.Now,
|
||||
BrokenElements = brokenElements,
|
||||
Broken_elements = brokenElements,
|
||||
Price = price,
|
||||
BusId = busId
|
||||
Bus_id = busId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -4,17 +4,17 @@ public class RouteList
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public TimeOnly Start { get; private set; }
|
||||
public TimeSpan Route_start { get; private set; }
|
||||
|
||||
public TimeOnly Finish { get; private set; }
|
||||
public TimeSpan Route_finish { get; private set; }
|
||||
|
||||
public static RouteList CreateEntity(int id, TimeOnly start, TimeOnly finish)
|
||||
public static RouteList CreateEntity(int id, TimeSpan start, TimeSpan finish)
|
||||
{
|
||||
return new RouteList
|
||||
{
|
||||
Id = id,
|
||||
Start = start,
|
||||
Finish = finish
|
||||
Route_start = start,
|
||||
Route_finish = finish
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ public class StartingShift
|
||||
|
||||
public DateTime Date { get; private set; }
|
||||
|
||||
public int RouteListId { get; private set; }
|
||||
public int Route_list_id { get; private set; }
|
||||
|
||||
public int BusId { get; private set; }
|
||||
public int Bus_id { get; private set; }
|
||||
|
||||
public IEnumerable<StartingShiftEmployee> StartingShiftEmployees { get; private set; } = [];
|
||||
public IEnumerable<StartingShiftEmployee> Starting_shift_employees { get; private set; } = [];
|
||||
|
||||
public static StartingShift CreateOperation(int id, int routeListId, int busId,
|
||||
IEnumerable<StartingShiftEmployee> startingShiftEmployees)
|
||||
@ -19,9 +19,9 @@ public class StartingShift
|
||||
{
|
||||
Id = id,
|
||||
Date = DateTime.Now,
|
||||
RouteListId = routeListId,
|
||||
BusId = busId,
|
||||
StartingShiftEmployees = startingShiftEmployees
|
||||
Route_list_id = routeListId,
|
||||
Bus_id = busId,
|
||||
Starting_shift_employees = startingShiftEmployees
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,19 @@
|
||||
|
||||
public class StartingShiftEmployee
|
||||
{
|
||||
public int StartingShiftId { get; private set; }
|
||||
public int Starting_shift_id { get; private set; }
|
||||
|
||||
public int EmployeeId { get; private set; }
|
||||
public int Employee_id { get; private set; }
|
||||
|
||||
public int WorkHours { get; private set; }
|
||||
public int Work_time { get; private set; }
|
||||
|
||||
public static StartingShiftEmployee CreateElement(int startingShiftId, int employeeId, int workHours)
|
||||
public static StartingShiftEmployee CreateElement(int startingShiftId, int employeeId, int workTime)
|
||||
{
|
||||
return new StartingShiftEmployee
|
||||
{
|
||||
StartingShiftId = startingShiftId,
|
||||
EmployeeId = employeeId,
|
||||
WorkHours = workHours
|
||||
Starting_shift_id = startingShiftId,
|
||||
Employee_id = employeeId,
|
||||
Work_time = workTime
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -28,30 +28,30 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
labelLicensePlate = new Label();
|
||||
textBoxLicensePlate = new TextBox();
|
||||
labelLicencePlate = new Label();
|
||||
textBoxLicencePlate = new TextBox();
|
||||
labelBusTypeName = new Label();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
textBoxModel = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelLicensePlate
|
||||
// labelLicencePlate
|
||||
//
|
||||
labelLicensePlate.AutoSize = true;
|
||||
labelLicensePlate.Location = new Point(27, 34);
|
||||
labelLicensePlate.Name = "labelLicensePlate";
|
||||
labelLicensePlate.Size = new Size(107, 30);
|
||||
labelLicensePlate.TabIndex = 0;
|
||||
labelLicensePlate.Text = "Госномер";
|
||||
labelLicencePlate.AutoSize = true;
|
||||
labelLicencePlate.Location = new Point(27, 34);
|
||||
labelLicencePlate.Name = "labelLicencePlate";
|
||||
labelLicencePlate.Size = new Size(107, 30);
|
||||
labelLicencePlate.TabIndex = 0;
|
||||
labelLicencePlate.Text = "Госномер";
|
||||
//
|
||||
// textBoxLicensePlate
|
||||
// textBoxLicencePlate
|
||||
//
|
||||
textBoxLicensePlate.Location = new Point(231, 31);
|
||||
textBoxLicensePlate.MaxLength = 10;
|
||||
textBoxLicensePlate.Name = "textBoxLicensePlate";
|
||||
textBoxLicensePlate.Size = new Size(240, 35);
|
||||
textBoxLicensePlate.TabIndex = 1;
|
||||
textBoxLicencePlate.Location = new Point(231, 31);
|
||||
textBoxLicencePlate.MaxLength = 10;
|
||||
textBoxLicencePlate.Name = "textBoxLicencePlate";
|
||||
textBoxLicencePlate.Size = new Size(240, 35);
|
||||
textBoxLicencePlate.TabIndex = 1;
|
||||
//
|
||||
// labelBusTypeName
|
||||
//
|
||||
@ -101,8 +101,8 @@
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(labelBusTypeName);
|
||||
Controls.Add(textBoxLicensePlate);
|
||||
Controls.Add(labelLicensePlate);
|
||||
Controls.Add(textBoxLicencePlate);
|
||||
Controls.Add(labelLicencePlate);
|
||||
Name = "FormBus";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Автобус";
|
||||
@ -112,8 +112,8 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelLicensePlate;
|
||||
private TextBox textBoxLicensePlate;
|
||||
private Label labelLicencePlate;
|
||||
private TextBox textBoxLicencePlate;
|
||||
private Label labelBusTypeName;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using ProjectPassengerTransportation.Entities;
|
||||
using ProjectPassengerTransportation.Entities.Enums;
|
||||
using ProjectPassengerTransportation.Repositories;
|
||||
|
||||
namespace ProjectPassengerTransportation.Forms
|
||||
@ -22,8 +21,8 @@ namespace ProjectPassengerTransportation.Forms
|
||||
throw new InvalidDataException(nameof(bus));
|
||||
}
|
||||
|
||||
textBoxLicensePlate.Text = bus.LicensePlate;
|
||||
comboBoxBusType.SelectedItem = bus.Model;
|
||||
textBoxLicencePlate.Text = bus.Licence_plate;
|
||||
textBoxModel.Text = bus.Model;
|
||||
_busId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -44,7 +43,7 @@ namespace ProjectPassengerTransportation.Forms
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxLicensePlate.Text) || string.IsNullOrWhiteSpace(textBoxModel.Text))
|
||||
if (string.IsNullOrWhiteSpace(textBoxLicencePlate.Text) || string.IsNullOrWhiteSpace(textBoxModel.Text))
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
@ -68,6 +67,6 @@ namespace ProjectPassengerTransportation.Forms
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
private Bus CreateBus(int id) => Bus.CreateEntity(id, textBoxLicensePlate.Text, textBoxModel.Text);
|
||||
private Bus CreateBus(int id) => Bus.CreateEntity(id, textBoxLicencePlate.Text, textBoxModel.Text);
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ namespace ProjectPassengerTransportation.Forms
|
||||
throw new InvalidDataException(nameof(employee));
|
||||
}
|
||||
|
||||
textBoxFirstName.Text = employee.FirstName;
|
||||
textBoxLastName.Text = employee.LastName;
|
||||
textBoxFirstName.Text = employee.First_name;
|
||||
textBoxLastName.Text = employee.Last_name;
|
||||
comboBoxPost.SelectedItem = employee.Post;
|
||||
_employeeId = value;
|
||||
}
|
||||
|
@ -93,6 +93,7 @@
|
||||
// numericUpDownPrice
|
||||
//
|
||||
numericUpDownPrice.Location = new Point(168, 310);
|
||||
numericUpDownPrice.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 });
|
||||
numericUpDownPrice.Name = "numericUpDownPrice";
|
||||
numericUpDownPrice.Size = new Size(245, 35);
|
||||
numericUpDownPrice.TabIndex = 21;
|
||||
|
@ -13,7 +13,7 @@ namespace ProjectPassengerTransportation.Forms
|
||||
InitializeComponent();
|
||||
_goToServiceRepository = goToServiceRepository ?? throw new ArgumentNullException(nameof(goToServiceRepository));
|
||||
comboBoxBus.DataSource = busRepository.ReadBuses();
|
||||
comboBoxBus.DisplayMember = "LicensePlate";
|
||||
comboBoxBus.DisplayMember = "Licence_plate";
|
||||
comboBoxBus.ValueMember = "Id";
|
||||
foreach (var elem in Enum.GetValues(typeof(BrokenElements)))
|
||||
{
|
||||
|
@ -21,10 +21,10 @@ namespace ProjectPassengerTransportation.Forms
|
||||
throw new InvalidDataException(nameof(routeList));
|
||||
}
|
||||
|
||||
numericUpDownStartHour.Value = routeList.Start.Hour;
|
||||
numericUpDownStartMin.Value = routeList.Start.Minute;
|
||||
numericUpDownFinishHour.Value = routeList.Finish.Hour;
|
||||
numericUpDownFinishMin.Value = routeList.Finish.Minute;
|
||||
numericUpDownStartHour.Value = (decimal)routeList.Route_start.Hours;
|
||||
numericUpDownStartMin.Value = (decimal)routeList.Route_start.Minutes;
|
||||
numericUpDownFinishHour.Value = (decimal)routeList.Route_finish.Hours;
|
||||
numericUpDownFinishMin.Value = (decimal)routeList.Route_finish.Minutes;
|
||||
_routeListId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -65,7 +65,7 @@ namespace ProjectPassengerTransportation.Forms
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
private RouteList CreateRouteList(int id) => RouteList.CreateEntity(id,
|
||||
new TimeOnly(Convert.ToInt32(numericUpDownStartHour.Value), Convert.ToInt32(numericUpDownStartMin.Value)),
|
||||
new TimeOnly(Convert.ToInt32(numericUpDownFinishHour.Value), Convert.ToInt32(numericUpDownFinishMin.Value)));
|
||||
new TimeSpan(Convert.ToInt32(numericUpDownStartHour.Value), Convert.ToInt32(numericUpDownStartMin.Value), 0),
|
||||
new TimeSpan(Convert.ToInt32(numericUpDownFinishHour.Value), Convert.ToInt32(numericUpDownFinishMin.Value), 0));
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,10 @@ namespace ProjectPassengerTransportation.Forms
|
||||
comboBoxRouteList.DisplayMember = "Id";
|
||||
comboBoxRouteList.ValueMember = "Id";
|
||||
comboBoxBus.DataSource = busRepository.ReadBuses();
|
||||
comboBoxBus.DisplayMember = "LicensePlate";
|
||||
comboBoxBus.DisplayMember = "Licence_plate";
|
||||
comboBoxBus.ValueMember = "Id";
|
||||
ColumnEmployees.DataSource = employeeRepository.ReadEmployees();
|
||||
ColumnEmployees.DisplayMember = "FirstName";
|
||||
ColumnEmployees.DisplayMember = "First_name";
|
||||
ColumnEmployees.ValueMember = "Id";
|
||||
}
|
||||
|
||||
@ -55,8 +55,8 @@ namespace ProjectPassengerTransportation.Forms
|
||||
var list = new List<StartingShiftEmployee>();
|
||||
foreach (DataGridViewRow row in dataGridViewEmployees.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnFeed"].Value == null ||
|
||||
row.Cells["ColumnCount"].Value == null)
|
||||
if (row.Cells["ColumnEmployees"].Value == null ||
|
||||
row.Cells["ColumnWorkHours"].Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -51,16 +51,16 @@
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 72;
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(845, 481);
|
||||
dataGridViewData.Size = new Size(1280, 636);
|
||||
dataGridViewData.TabIndex = 5;
|
||||
//
|
||||
// panelButtons
|
||||
//
|
||||
panelButtons.Controls.Add(buttonAdd);
|
||||
panelButtons.Dock = DockStyle.Right;
|
||||
panelButtons.Location = new Point(845, 0);
|
||||
panelButtons.Location = new Point(1280, 0);
|
||||
panelButtons.Name = "panelButtons";
|
||||
panelButtons.Size = new Size(196, 481);
|
||||
panelButtons.Size = new Size(196, 636);
|
||||
panelButtons.TabIndex = 4;
|
||||
//
|
||||
// buttonAdd
|
||||
@ -78,7 +78,7 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(12F, 30F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1041, 481);
|
||||
ClientSize = new Size(1476, 636);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panelButtons);
|
||||
Name = "FormStartingShifts";
|
||||
|
@ -3,7 +3,6 @@ using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectPassengerTransportation.Entities;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||
|
||||
@ -28,8 +27,8 @@ public class BusRepository : IBusRepository
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO bus (licence_plate, bus_type_id)
|
||||
VALUES (@LicencePlate, @Type)";
|
||||
INSERT INTO bus (licence_plate, model)
|
||||
VALUES (@Licence_plate, @Model)";
|
||||
connection.Execute(queryInsert, bus);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -50,8 +49,8 @@ VALUES (@LicencePlate, @Type)";
|
||||
var queryUpdate = @"
|
||||
UPDATE bus
|
||||
SET
|
||||
licence_plate=@LicencePlate,
|
||||
bus_type_id=@Type
|
||||
licence_plate=@Licence_plate,
|
||||
model=@Model
|
||||
WHERE id=@Id";
|
||||
connection.Execute(queryUpdate, bus);
|
||||
}
|
||||
@ -82,18 +81,18 @@ WHERE id=@id";
|
||||
}
|
||||
}
|
||||
|
||||
public Bus ReadBusById(int id)
|
||||
public Bus ReadBusById(int busId)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
_logger.LogDebug("Объект: {id}", busId);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM bus
|
||||
WHERE [id]=@id";
|
||||
var bus = connection.QueryFirst<Bus>(querySelect, new { id });
|
||||
WHERE id=@busId";
|
||||
var bus = connection.QueryFirst<Bus>(querySelect, new { busId });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(bus));
|
||||
|
||||
return bus;
|
||||
@ -111,7 +110,7 @@ WHERE [id]=@id";
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM bus";
|
||||
var querySelect = @"SELECT * FROM bus";
|
||||
var buses = connection.Query<Bus>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(buses));
|
||||
return buses;
|
||||
|
@ -1,32 +1,125 @@
|
||||
using ProjectPassengerTransportation.Entities;
|
||||
using ProjectPassengerTransportation.Entities.Enums;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectPassengerTransportation.Entities;
|
||||
|
||||
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||
|
||||
public class EmployeeRepository : IEmployeeRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<EmployeeRepository> _logger;
|
||||
|
||||
public EmployeeRepository(IConnectionString connectionString, ILogger<EmployeeRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateEmployee(Employee employee)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(employee));
|
||||
|
||||
}
|
||||
|
||||
public void DeleteEmployee(int id)
|
||||
try
|
||||
{
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO employee (first_name, last_name, post)
|
||||
VALUES (@First_name, @Last_name, @Post)";
|
||||
connection.Execute(queryInsert, employee);
|
||||
}
|
||||
|
||||
public Employee ReadEmployeeById(int employeeId)
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Employee.CreateEntity(0, string.Empty, string.Empty, EmployeePost.None);
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
public IEnumerable<Employee> ReadEmployees()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public void UpdateEmployee(Employee employee)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(employee));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE employee
|
||||
SET
|
||||
first_name=@First_name,
|
||||
last_name=@Last_name,
|
||||
post=@Post
|
||||
WHERE id=@Id";
|
||||
connection.Execute(queryUpdate, employee);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteEmployee(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM employee
|
||||
WHERE id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Employee ReadEmployeeById(int employeeId)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", employeeId);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM employee
|
||||
WHERE id=@employeeId";
|
||||
var employee = connection.QueryFirst<Employee>(querySelect, new { employeeId });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(employee));
|
||||
|
||||
return employee;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Employee> ReadEmployees()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM employee";
|
||||
var employees = connection.Query<Employee>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(employees));
|
||||
return employees;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,80 @@
|
||||
using ProjectPassengerTransportation.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectPassengerTransportation.Entities;
|
||||
using ProjectPassengerTransportation.Entities.Enums;
|
||||
|
||||
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||
|
||||
public class GoToServiceRepository : IGoToServiceRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<GoToServiceRepository> _logger;
|
||||
|
||||
public GoToServiceRepository(IConnectionString connectionString, ILogger<GoToServiceRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateGoToService(GoToService goToService)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(goToService));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO go_to_service (date, price, bus_id, broken_elements)
|
||||
VALUES (@Date, @Price, @Bus_id, @Broken_elements)";
|
||||
connection.Execute(queryInsert, goToService);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteGoToService(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<GoToService> ReadServices(DateTime? dateFrom = null, DateTime? dateTo = null, BrokenElements BrokenElements = BrokenElements.None, int? price = null, int? busId = null)
|
||||
try
|
||||
{
|
||||
return [];
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM go_to_service
|
||||
WHERE id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<GoToService> ReadServices(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||
BrokenElements BrokenElements = BrokenElements.None, int? price = null, int? busId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM go_to_service";
|
||||
var services = connection.Query<GoToService>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(services));
|
||||
return services;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,125 @@
|
||||
using ProjectPassengerTransportation.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectPassengerTransportation.Entities;
|
||||
using System;
|
||||
|
||||
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||
|
||||
public class RouteListRepository : IRouteListRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<RouteListRepository> _logger;
|
||||
|
||||
public RouteListRepository(IConnectionString connectionString, ILogger<RouteListRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateRouteList(RouteList routeList)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(routeList));
|
||||
|
||||
}
|
||||
|
||||
public void DeleteRouteList(int id)
|
||||
try
|
||||
{
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO route_list (route_start, route_finish)
|
||||
VALUES (@Route_start, @Route_finish)";
|
||||
connection.Execute(queryInsert, routeList);
|
||||
}
|
||||
|
||||
public RouteList ReadRouteListById(int routeListId)
|
||||
catch (Exception ex)
|
||||
{
|
||||
return RouteList.CreateEntity(0, new TimeOnly(0, 0), new TimeOnly(0, 0));
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
public IEnumerable<RouteList> ReadRouteLists()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public void UpdateRouteList(RouteList routeList)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(routeList));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE route_list
|
||||
SET
|
||||
route_start=@Route_start,
|
||||
route_finish=@Route_finish
|
||||
WHERE id=@Id";
|
||||
connection.Execute(queryUpdate, routeList);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteRouteList(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM route_list
|
||||
WHERE id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public RouteList ReadRouteListById(int routeListId)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", routeListId);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM route_list
|
||||
WHERE id=@routeListId";
|
||||
var routeList = connection.QueryFirst<RouteList>(querySelect, new { routeListId });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(routeList));
|
||||
|
||||
return routeList;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<RouteList> ReadRouteLists()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM route_list";
|
||||
var routeLists = connection.Query<RouteList>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routeLists));
|
||||
return routeLists;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,70 @@
|
||||
using ProjectPassengerTransportation.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectPassengerTransportation.Entities;
|
||||
|
||||
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||
|
||||
public class StartingShiftRepository : IStartingShiftRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
|
||||
private readonly ILogger<StartingShiftRepository> _logger;
|
||||
|
||||
public StartingShiftRepository(IConnectionString connectionString, ILogger<StartingShiftRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateStartingShift(StartingShift startingShift)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(startingShift));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO starting_shift (date, route_list_id, bus_id)
|
||||
VALUES (@Date, @Route_list_id, @Bus_id);
|
||||
SELECT MAX(Id) FROM starting_shift";
|
||||
var starting_shift_id = connection.QueryFirst<int>(queryInsert, startingShift, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO starting_shift_employee (starting_shift_id, employee_id, work_time)
|
||||
VALUES (@Starting_shift_id, @Employee_id, @Work_time)";
|
||||
foreach (var elem in startingShift.Starting_shift_employees)
|
||||
{
|
||||
connection.Execute(querySubInsert, new { starting_shift_id, elem.Employee_id, elem.Work_time }, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<StartingShift> ReadShifts(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||
int? routeListId = null, int? employeeId = null, int? busId = null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM starting_shift";
|
||||
var startingShifts = connection.Query<StartingShift>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(startingShifts));
|
||||
return startingShifts;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user