Что-то было сделано
This commit is contained in:
parent
44c4998db1
commit
2bb556bc3f
@ -15,6 +15,7 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||||
<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.0.2" />
|
<PackageReference Include="Serilog" Version="4.0.2" />
|
||||||
<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" />
|
||||||
|
@ -38,7 +38,7 @@ namespace Accounting_Time_It_Company.Forms
|
|||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
|
|
||||||
_typeJobRepositories.CreateTypeJob(TypeJob.CreateOperation(0, (int)comboBoxProduct.SelectedIndex!, textBoxDescriptoin.Text,
|
_typeJobRepositories.CreateTypeJob(TypeJob.CreateOperation(0, (int)comboBoxProduct.SelectedValue!, textBoxDescriptoin.Text,
|
||||||
(int)numericUpDownAllowanceForJob.Value, CreateListWorkTimeFromDataGrid(dataGridViewDevelops),
|
(int)numericUpDownAllowanceForJob.Value, CreateListWorkTimeFromDataGrid(dataGridViewDevelops),
|
||||||
CreateListWorkTimeFromDataGrid(dataGridViewManagers)));
|
CreateListWorkTimeFromDataGrid(dataGridViewManagers)));
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ namespace Accounting_Time_It_Company.Forms
|
|||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
|
|
||||||
_vacationRepositories.CreateVacation(Vacation.CreateOpeartion(0, (int)comboBoxEmployee.SelectedIndex!,
|
_vacationRepositories.CreateVacation(Vacation.CreateOpeartion(0, (int)comboBoxEmployee.SelectedValue!,
|
||||||
dateTimePickerStartDate.Value, dateTimePickerEndDate.Value));
|
dateTimePickerStartDate.Value, dateTimePickerEndDate.Value));
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
#pragma warning disable CS0618
|
#pragma warning disable CS0618
|
||||||
|
|
||||||
@ -25,10 +26,11 @@ internal class ClientRepositories : IClientRepositories
|
|||||||
_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);
|
||||||
|
connection.Open();
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Client (NameClient, Phone)
|
INSERT INTO Client
|
||||||
VALUES (@NameClient, @Phone)";
|
VALUES (DEFAULT, @NameClient, @Phone)";
|
||||||
connection.Execute(queryInsert, client);
|
connection.Execute(queryInsert, client);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -44,8 +46,8 @@ internal class ClientRepositories : IClientRepositories
|
|||||||
JsonConvert.SerializeObject(client));
|
JsonConvert.SerializeObject(client));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
var queryUpdate = @"
|
var queryUpdate = @"
|
||||||
UPDATE Client
|
UPDATE Client
|
||||||
SET
|
SET
|
||||||
@ -67,7 +69,8 @@ internal class ClientRepositories : IClientRepositories
|
|||||||
_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();
|
||||||
var queryDelete = @"
|
var queryDelete = @"
|
||||||
DELETE FROM Client
|
DELETE FROM Client
|
||||||
WHERE Id=@id";
|
WHERE Id=@id";
|
||||||
@ -86,7 +89,8 @@ internal class ClientRepositories : IClientRepositories
|
|||||||
_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();
|
||||||
var querySelect = @"
|
var querySelect = @"
|
||||||
SELECT * FROM Client
|
SELECT * FROM Client
|
||||||
WHERE Id=@id";
|
WHERE Id=@id";
|
||||||
@ -106,7 +110,8 @@ internal class ClientRepositories : IClientRepositories
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
var querySelect = "SELECT * FROM Client";
|
var querySelect = "SELECT * FROM Client";
|
||||||
var clients = connection.Query<Client>(querySelect);
|
var clients = connection.Query<Client>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
@ -3,5 +3,5 @@ namespace Accounting_Time_It_Company.Repositories.Implementations;
|
|||||||
|
|
||||||
public class ConnectionString : IConnectionString
|
public class ConnectionString : IConnectionString
|
||||||
{
|
{
|
||||||
string IConnectionString.ConnectionString => "";
|
string IConnectionString.ConnectionString => "Server=localhost:5432;Database=workTime;User Id=postgres;Password=postgres;";
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Data.SqlClient;
|
using Npgsql;
|
||||||
|
|
||||||
namespace Accounting_Time_It_Company.Repositories.Implementations;
|
namespace Accounting_Time_It_Company.Repositories.Implementations;
|
||||||
|
|
||||||
@ -24,10 +24,11 @@ public class EmployeeRepositories : IEmployeeRepositories
|
|||||||
_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);
|
||||||
|
connection.Open();
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Employee (PostId, Name, Phone, Allowance)
|
INSERT INTO Employee
|
||||||
VALUES (@PostId, @Name, @Phone, @Allowance)";
|
VALUES (DEFAULT, @PostId, @Name, @Phone, @Allowance)";
|
||||||
connection.Execute(queryInsert, employee);
|
connection.Execute(queryInsert, employee);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -44,8 +45,8 @@ public class EmployeeRepositories : IEmployeeRepositories
|
|||||||
JsonConvert.SerializeObject(employee));
|
JsonConvert.SerializeObject(employee));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
var queryUpdate = @"
|
var queryUpdate = @"
|
||||||
UPDATE Employee
|
UPDATE Employee
|
||||||
SET
|
SET
|
||||||
@ -69,7 +70,8 @@ public class EmployeeRepositories : IEmployeeRepositories
|
|||||||
_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();
|
||||||
var queryDelete = @"
|
var queryDelete = @"
|
||||||
DELETE FROM Employee
|
DELETE FROM Employee
|
||||||
WHERE Id=@id";
|
WHERE Id=@id";
|
||||||
@ -88,7 +90,8 @@ public class EmployeeRepositories : IEmployeeRepositories
|
|||||||
_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();
|
||||||
var querySelect = @"
|
var querySelect = @"
|
||||||
SELECT * FROM Employee
|
SELECT * FROM Employee
|
||||||
WHERE [Id]=@id";
|
WHERE [Id]=@id";
|
||||||
@ -108,7 +111,8 @@ public class EmployeeRepositories : IEmployeeRepositories
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
var querySelect = "SELECT * FROM Employee";
|
var querySelect = "SELECT * FROM Employee";
|
||||||
var employees = connection.Query<Employee>(querySelect);
|
var employees = connection.Query<Employee>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Data.SqlClient;
|
using Npgsql;
|
||||||
|
|
||||||
namespace Accounting_Time_It_Company.Repositories.Implementations;
|
namespace Accounting_Time_It_Company.Repositories.Implementations;
|
||||||
|
|
||||||
@ -24,10 +24,11 @@ public class PostRepositories : IPostRepositories
|
|||||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(post));
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(post));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Post (NamePost, LevelPost, Wage)
|
INSERT INTO Post
|
||||||
VALUES (@NamePost, @LevelPost, @Wage)";
|
VALUES (DEFAULT, @NamePost, @LevelPost, @Wage)";
|
||||||
connection.Execute(queryInsert, post);
|
connection.Execute(queryInsert, post);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -44,8 +45,8 @@ public class PostRepositories : IPostRepositories
|
|||||||
JsonConvert.SerializeObject(post));
|
JsonConvert.SerializeObject(post));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
var queryUpdate = @"
|
var queryUpdate = @"
|
||||||
UPDATE Post
|
UPDATE Post
|
||||||
SET
|
SET
|
||||||
@ -68,7 +69,8 @@ public class PostRepositories : IPostRepositories
|
|||||||
_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();
|
||||||
var queryDelete = @"
|
var queryDelete = @"
|
||||||
DELETE FROM Post
|
DELETE FROM Post
|
||||||
WHERE Id=@id";
|
WHERE Id=@id";
|
||||||
@ -87,7 +89,8 @@ public class PostRepositories : IPostRepositories
|
|||||||
_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();
|
||||||
var querySelect = @"
|
var querySelect = @"
|
||||||
SELECT * FROM Post
|
SELECT * FROM Post
|
||||||
WHERE Id=@id";
|
WHERE Id=@id";
|
||||||
@ -107,7 +110,8 @@ public class PostRepositories : IPostRepositories
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
var querySelect = "SELECT * FROM Post";
|
var querySelect = "SELECT * FROM Post";
|
||||||
var posts = connection.Query<Post>(querySelect);
|
var posts = connection.Query<Post>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Data.SqlClient;
|
using Npgsql;
|
||||||
|
|
||||||
namespace Accounting_Time_It_Company.Repositories.Implementations;
|
namespace Accounting_Time_It_Company.Repositories.Implementations;
|
||||||
|
|
||||||
@ -21,13 +21,14 @@ public class ProductRepositories : IProductRepositories
|
|||||||
public void CreateProduct(Product product)
|
public void CreateProduct(Product product)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Добавление объекта");
|
_logger.LogInformation("Добавление объекта");
|
||||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(post));
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Product (ClientId, Name, Type)
|
INSERT INTO Product
|
||||||
VALUES (@ClientId, @Name, @Type)";
|
VALUES (DEFAULT, @ClientId, @Name, @Type)";
|
||||||
connection.Execute(queryInsert, product);
|
connection.Execute(queryInsert, product);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -44,8 +45,8 @@ public class ProductRepositories : IProductRepositories
|
|||||||
JsonConvert.SerializeObject(product));
|
JsonConvert.SerializeObject(product));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
var queryUpdate = @"
|
var queryUpdate = @"
|
||||||
UPDATE Product
|
UPDATE Product
|
||||||
SET
|
SET
|
||||||
@ -68,7 +69,8 @@ public class ProductRepositories : IProductRepositories
|
|||||||
_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();
|
||||||
var queryDelete = @"
|
var queryDelete = @"
|
||||||
DELETE FROM Product
|
DELETE FROM Product
|
||||||
WHERE Id=@id";
|
WHERE Id=@id";
|
||||||
@ -87,7 +89,8 @@ public class ProductRepositories : IProductRepositories
|
|||||||
_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();
|
||||||
var querySelect = @"
|
var querySelect = @"
|
||||||
SELECT * FROM Product
|
SELECT * FROM Product
|
||||||
WHERE [Id]=@id";
|
WHERE [Id]=@id";
|
||||||
@ -107,7 +110,8 @@ public class ProductRepositories : IProductRepositories
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new SqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
var querySelect = "SELECT * FROM Product";
|
var querySelect = "SELECT * FROM Product";
|
||||||
var products = connection.Query<Product>(querySelect);
|
var products = connection.Query<Product>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
@ -1,19 +1,107 @@
|
|||||||
using Accounting_Time_It_Company.Entities;
|
using Accounting_Time_It_Company.Entities;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
|
||||||
namespace Accounting_Time_It_Company.Repositories.Implementations;
|
namespace Accounting_Time_It_Company.Repositories.Implementations;
|
||||||
|
|
||||||
public class TypeJobRepositories : ITypeJobRepositories
|
public class TypeJobRepositories : ITypeJobRepositories
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<TypeJobRepositories> _logger;
|
||||||
|
|
||||||
|
public TypeJobRepositories(IConnectionString connectionString, ILogger<TypeJobRepositories> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateTypeJob(TypeJob typeJob)
|
public void CreateTypeJob(TypeJob typeJob)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(typeJob));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO TypeJob
|
||||||
|
VALUES (DEFAULT, @ProductId, @Description, @AllowanceForJob, @Date, @WorkTimesDevelop, @WorkTimesManager);
|
||||||
|
SELECT MAX(Id) FROM TypeJob";
|
||||||
|
var typeJobId = connection.QueryFirst<int>(queryInsert, typeJob, transaction);
|
||||||
|
var querySubInsert = @"
|
||||||
|
INSERT INTO WorkTime
|
||||||
|
VALUES (DEFAULT, @TypeJobId, @EmployeeId, @Hours)";
|
||||||
|
foreach (var elem in typeJob.WorkTimesDevelop)
|
||||||
|
{
|
||||||
|
connection.Execute(querySubInsert, new
|
||||||
|
{
|
||||||
|
typeJobId,
|
||||||
|
elem.EmployeeId,
|
||||||
|
elem.Hours
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var elem in typeJob.WorkTimesManager)
|
||||||
|
{
|
||||||
|
connection.Execute(querySubInsert, new
|
||||||
|
{
|
||||||
|
typeJobId,
|
||||||
|
elem.EmployeeId,
|
||||||
|
elem.Hours
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteTypeJob(int id)
|
public void DeleteTypeJob(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM TypeJob
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<TypeJob> ReadTypeJobs(int? productId = null, int? developId = null, int? managerId = null)
|
public IEnumerable<TypeJob> ReadTypeJobs(int? productId = null, int? developId = null, int? managerId = null)
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
var querySelect = @"SELECT * FROM TypeJob";
|
||||||
|
var typeJobs = connection.Query<TypeJob>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(typeJobs));
|
||||||
|
return typeJobs;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,62 @@
|
|||||||
using Accounting_Time_It_Company.Entities;
|
using Accounting_Time_It_Company.Entities;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
|
||||||
namespace Accounting_Time_It_Company.Repositories.Implementations;
|
namespace Accounting_Time_It_Company.Repositories.Implementations;
|
||||||
|
|
||||||
public class VacationRepositories : IVacationRepositories
|
public class VacationRepositories : IVacationRepositories
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<VacationRepositories> _logger;
|
||||||
|
|
||||||
|
public VacationRepositories(IConnectionString connectionString, ILogger<VacationRepositories> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateVacation(Vacation vacation)
|
public void CreateVacation(Vacation vacation)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(vacation));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Vacation
|
||||||
|
VALUES (DEFAULT, @EmployeeId, @StartDate, @EndDate)";
|
||||||
|
connection.Execute(queryInsert, vacation);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Vacation> ReadVacations(DateTime? startDateFrom = null, DateTime? startDateTo = null,
|
public IEnumerable<Vacation> ReadVacations(DateTime? startDateFrom = null, DateTime? startDateTo = null,
|
||||||
DateTime? endDateFrom = null, DateTime? endtDateTo = null, int? employeeId = null)
|
DateTime? endDateFrom = null, DateTime? endtDateTo = null, int? employeeId = null)
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
var querySelect = "SELECT * FROM Vacation";
|
||||||
|
var vacations = connection.Query<Vacation>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(vacations));
|
||||||
|
return vacations;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user