Spaces:
Runtime error
Runtime error
Download src/SCM.Infrastructure/Persistence/Repositories/CriterioEapItemRepository.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 2.54 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Persistence/Repositories/CriterioEapItemRepository.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Infrastructure/Persistence/Repositories/CriterioEapItemRepository.cs
-
curl -L -o CriterioEapItemRepository.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Persistence/Repositories/CriterioEapItemRepository.cs
2.54 kB
| using System.Data; | |
| using Dapper; | |
| using SCM.Application.Common; | |
| using SCM.Domain.Medicao; | |
| namespace SCM.Infrastructure.Persistence.Repositories; | |
| public sealed class CriterioEapItemRepository : ICriterioEapItemRepository | |
| { | |
| private readonly IUnitOfWork _uow; | |
| public CriterioEapItemRepository(IUnitOfWork uow) => _uow = uow; | |
| private IDbConnection Conn => _uow.Connection; | |
| private IDbTransaction? Tx => _uow.CurrentTransaction; | |
| public async Task<IReadOnlyList<CriterioEapItem>> GetByCriterioAsync(Guid criterioEapId, CancellationToken ct = default) | |
| { | |
| const string sql = """ | |
| SELECT id, criterio_eap_id, sub_atividade_padrao_id, percentual | |
| FROM criterio_eap_itens WHERE criterio_eap_id = @Id ORDER BY percentual DESC | |
| """; | |
| var rows = await Conn.QueryAsync<CriterioEapItem>( | |
| new CommandDefinition(sql, new { Id = criterioEapId }, Tx, cancellationToken: ct)); | |
| return rows.ToList(); | |
| } | |
| public async Task<bool> CriterioExistsAsync(Guid criterioEapId, CancellationToken ct = default) | |
| { | |
| const string sql = "SELECT COUNT(*) FROM criterios_eap WHERE id = @Id"; | |
| var count = await Conn.ExecuteScalarAsync<long>( | |
| new CommandDefinition(sql, new { Id = criterioEapId }, Tx, cancellationToken: ct)); | |
| return count > 0; | |
| } | |
| public async Task<bool> SubAtividadeExistsAsync(Guid subAtividadePadraoId, CancellationToken ct = default) | |
| { | |
| const string sql = "SELECT COUNT(*) FROM subativs_padrao WHERE id = @Id"; | |
| var count = await Conn.ExecuteScalarAsync<long>( | |
| new CommandDefinition(sql, new { Id = subAtividadePadraoId }, Tx, cancellationToken: ct)); | |
| return count > 0; | |
| } | |
| public async Task ReplaceAsync(Guid criterioEapId, IReadOnlyList<CriterioEapItem> itens, CancellationToken ct = default) | |
| { | |
| await Conn.ExecuteAsync(new CommandDefinition( | |
| "DELETE FROM criterio_eap_itens WHERE criterio_eap_id = @Id", | |
| new { Id = criterioEapId }, Tx, cancellationToken: ct)); | |
| const string sql = """ | |
| INSERT INTO criterio_eap_itens (id, criterio_eap_id, sub_atividade_padrao_id, percentual) | |
| VALUES (@Id, @CriterioEapId, @SubAtividadePadraoId, @Percentual) | |
| """; | |
| foreach (var i in itens) | |
| await Conn.ExecuteAsync(new CommandDefinition(sql, new | |
| { | |
| i.Id, i.CriterioEapId, i.SubAtividadePadraoId, i.Percentual | |
| }, Tx, cancellationToken: ct)); | |
| } | |
| } | |