Spaces:
Runtime error
Runtime error
Download src/SCM.Infrastructure/Persistence/Repositories/CronogramaAtividadeRepository.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 3.18 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Persistence/Repositories/CronogramaAtividadeRepository.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Infrastructure/Persistence/Repositories/CronogramaAtividadeRepository.cs
-
curl -L -o CronogramaAtividadeRepository.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Persistence/Repositories/CronogramaAtividadeRepository.cs
3.18 kB
| using System.Data; | |
| using Dapper; | |
| using SCM.Application.Common; | |
| using SCM.Domain.Controle; | |
| namespace SCM.Infrastructure.Persistence.Repositories; | |
| public sealed class CronogramaAtividadeRepository : ICronogramaAtividadeRepository | |
| { | |
| private readonly IUnitOfWork _uow; | |
| public CronogramaAtividadeRepository(IUnitOfWork uow) => _uow = uow; | |
| private IDbConnection Conn => _uow.Connection; | |
| private IDbTransaction? Tx => _uow.CurrentTransaction; | |
| private const string Columns = | |
| "id, item_programado_id, data_inicio_prevista, data_fim_prevista, percentual_previsto, activity_id, projeto_id"; | |
| public async Task<CronogramaAtividade?> GetByItemProgramadoAsync(Guid itemProgramadoId, CancellationToken ct = default) | |
| { | |
| const string sql = $"SELECT {Columns} FROM cronograma_atividades WHERE item_programado_id = @Id"; | |
| return await Conn.QueryFirstOrDefaultAsync<CronogramaAtividade>( | |
| new CommandDefinition(sql, new { Id = itemProgramadoId }, Tx, cancellationToken: ct)); | |
| } | |
| public async Task<bool> ItemProgramadoExistsAsync(Guid itemProgramadoId, CancellationToken ct = default) | |
| { | |
| const string sql = "SELECT COUNT(*) FROM itens_programados WHERE id = @Id"; | |
| var count = await Conn.ExecuteScalarAsync<long>( | |
| new CommandDefinition(sql, new { Id = itemProgramadoId }, Tx, cancellationToken: ct)); | |
| return count > 0; | |
| } | |
| public async Task AddAsync(CronogramaAtividade c, CancellationToken ct = default) | |
| { | |
| const string sql = """ | |
| INSERT INTO cronograma_atividades | |
| (id, item_programado_id, data_inicio_prevista, data_fim_prevista, percentual_previsto, activity_id, projeto_id) | |
| VALUES | |
| (@Id, @ItemProgramadoId, @DataInicioPrevista, @DataFimPrevista, @PercentualPrevisto, @ActivityId, @ProjetoId) | |
| """; | |
| await Conn.ExecuteAsync(new CommandDefinition(sql, ToParameters(c), Tx, cancellationToken: ct)); | |
| } | |
| public async Task UpdateAsync(CronogramaAtividade c, CancellationToken ct = default) | |
| { | |
| const string sql = """ | |
| UPDATE cronograma_atividades | |
| SET data_inicio_prevista = @DataInicioPrevista, data_fim_prevista = @DataFimPrevista, | |
| percentual_previsto = @PercentualPrevisto, activity_id = @ActivityId, projeto_id = @ProjetoId | |
| WHERE id = @Id | |
| """; | |
| await Conn.ExecuteAsync(new CommandDefinition(sql, ToParameters(c), Tx, cancellationToken: ct)); | |
| } | |
| public async Task<bool> DeleteByItemProgramadoAsync(Guid itemProgramadoId, CancellationToken ct = default) | |
| { | |
| const string sql = "DELETE FROM cronograma_atividades WHERE item_programado_id = @Id"; | |
| var affected = await Conn.ExecuteAsync( | |
| new CommandDefinition(sql, new { Id = itemProgramadoId }, Tx, cancellationToken: ct)); | |
| return affected > 0; | |
| } | |
| private static object ToParameters(CronogramaAtividade c) => new | |
| { | |
| c.Id, | |
| c.ItemProgramadoId, | |
| c.DataInicioPrevista, | |
| c.DataFimPrevista, | |
| c.PercentualPrevisto, | |
| c.ActivityId, | |
| c.ProjetoId | |
| }; | |
| } | |