правки 3
This commit is contained in:
parent
1b125123e4
commit
f1094a0164
@ -15,6 +15,7 @@ internal class ModelRepository : IModelRepository
|
|||||||
_connectionString = connectionString;
|
_connectionString = connectionString;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateModel(Model model)
|
public void CreateModel(Model model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Добавление объекта");
|
_logger.LogInformation("Добавление объекта");
|
||||||
@ -108,10 +109,22 @@ internal class ModelRepository : IModelRepository
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
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
|
DELETE FROM Models
|
||||||
WHERE Id = @id";
|
WHERE Id = @Id";
|
||||||
connection.Execute(queryDelete, new { id });
|
|
||||||
|
connection.Execute(queryDeleteModel, new { Id = id }, transaction);
|
||||||
|
|
||||||
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -142,7 +155,6 @@ internal class ModelRepository : IModelRepository
|
|||||||
}
|
}
|
||||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(model));
|
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(model));
|
||||||
|
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -152,19 +164,15 @@ internal class ModelRepository : IModelRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<Model> ReadModels()
|
public IEnumerable<Model> ReadModels()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
NpgsqlConnection(_connectionString.ConnectionString);
|
|
||||||
var querySelect = "SELECT * FROM Models";
|
var querySelect = "SELECT * FROM Models";
|
||||||
var models = connection.Query<Model>(querySelect);
|
var models = connection.Query<Model>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(models));
|
||||||
JsonConvert.SerializeObject(models));
|
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
Loading…
Reference in New Issue
Block a user