правки 3

This commit is contained in:
vettaql 2025-01-30 18:46:46 +04:00
parent 1b125123e4
commit f1094a0164

View File

@ -15,6 +15,7 @@ internal class ModelRepository : IModelRepository
_connectionString = connectionString;
_logger = logger;
}
public void CreateModel(Model model)
{
_logger.LogInformation("Добавление объекта");
@ -108,10 +109,22 @@ internal class ModelRepository : IModelRepository
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
connection.Open();
using var transaction = connection.BeginTransaction();
var queryDeleteFabricModel = @"
DELETE FROM FabricModel
WHERE ModelId = @Id";
connection.Execute(queryDeleteFabricModel, new { Id = id }, transaction);
var queryDeleteModel = @"
DELETE FROM Models
WHERE Id = @id";
connection.Execute(queryDelete, new { id });
WHERE Id = @Id";
connection.Execute(queryDeleteModel, new { Id = id }, transaction);
transaction.Commit();
}
catch (Exception ex)
{
@ -142,7 +155,6 @@ internal class ModelRepository : IModelRepository
}
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(model));
return model;
}
catch (Exception ex)
@ -152,19 +164,15 @@ internal class ModelRepository : IModelRepository
}
}
public IEnumerable<Model> ReadModels()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Models";
var models = connection.Query<Model>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(models));
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(models));
return models;
}
catch (Exception ex)