Fase 2: Implementación de la Matriz de Operaciones (Backend & Frontend)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using SIGCM.Domain.Entities;
|
||||
using SIGCM.Domain.Interfaces;
|
||||
using SIGCM.Infrastructure.Data;
|
||||
@@ -57,4 +58,38 @@ public class CategoryRepository : ICategoryRepository
|
||||
using var conn = _connectionFactory.CreateConnection();
|
||||
return await conn.QueryAsync<Category>("SELECT * FROM Categories WHERE ParentId = @ParentId", new { ParentId = parentId });
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Operation>> GetOperationsAsync(int categoryId)
|
||||
{
|
||||
using var conn = _connectionFactory.CreateConnection();
|
||||
var sql = @"
|
||||
SELECT o.*
|
||||
FROM Operations o
|
||||
INNER JOIN CategoryOperations co ON o.Id = co.OperationId
|
||||
WHERE co.CategoryId = @CategoryId";
|
||||
return await conn.QueryAsync<Operation>(sql, new { CategoryId = categoryId });
|
||||
}
|
||||
|
||||
public async Task AddOperationAsync(int categoryId, int operationId)
|
||||
{
|
||||
using var conn = _connectionFactory.CreateConnection();
|
||||
var sql = "INSERT INTO CategoryOperations (CategoryId, OperationId) VALUES (@CategoryId, @OperationId)";
|
||||
try
|
||||
{
|
||||
await conn.ExecuteAsync(sql, new { CategoryId = categoryId, OperationId = operationId });
|
||||
}
|
||||
catch (SqlException)
|
||||
{
|
||||
// Ignore duplicate key errors if it already exists
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RemoveOperationAsync(int categoryId, int operationId)
|
||||
{
|
||||
using var conn = _connectionFactory.CreateConnection();
|
||||
await conn.ExecuteAsync(
|
||||
"DELETE FROM CategoryOperations WHERE CategoryId = @CategoryId AND OperationId = @OperationId",
|
||||
new { CategoryId = categoryId, OperationId = operationId });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user