правки 3
This commit is contained in:
parent
1b125123e4
commit
f1094a0164
@ -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)
|
||||
{
|
||||
@ -141,7 +154,6 @@ internal class ModelRepository : IModelRepository
|
||||
throw new KeyNotFoundException($"Модель с идентификатором {id} не найдена");
|
||||
}
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(model));
|
||||
|
||||
|
||||
return model;
|
||||
}
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user