using System.Data.Common; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using MMDAL.DTO.PartLevel; using MMDAL.Query.PartLevel; namespace MMDAL.CustomCode.PartLevel { public class PartAllocationDAL : IPartAllocationDAL { private readonly IQueryExecutor _QueryExecutor; public PartAllocationDAL(IQueryExecutor queryExecutor) => _QueryExecutor = queryExecutor; public async Task> GetPartAllocationList( int partDetailId, LoginDTO loginDTO, CancellationToken ct) => await _QueryExecutor .QueryAsync(loginDTO, PartAllocationQB.GET_PARTALLOCATION_LIST, new { PartDetailId = partDetailId }, cancellationToken: ct) .ConfigureAwait(false) ?? []; public async Task GetPartAllocation( int partAllocationId, LoginDTO loginDTO, CancellationToken ct) => await _QueryExecutor .QuerySingleAsync(loginDTO, PartAllocationQB.GET_PARTALLOCATION, new { PartAllocationId = partAllocationId }, cancellationToken: ct) .ConfigureAwait(false); public async Task InsertPartAllocation( PartAllocationDTO dto, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) { dto.CreatedById = loginDTO.UserId; dto.CreatedOn = DateTime.UtcNow; dto.ModifiedById = loginDTO.UserId; dto.ModifiedOn = DateTime.UtcNow; await _QueryExecutor .ExecuteAsync(loginDTO, PartAllocationQB.INSERT_PARTALLOCATION, dto, tx, cancellationToken: ct) .ConfigureAwait(false); } public async Task UpdateIssued( int partAllocationId, decimal quantity, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) => await _QueryExecutor .ExecuteAsync(loginDTO, PartAllocationQB.UPDATE_ISSUED, new { PartAllocationId = partAllocationId, Quantity = quantity, ModifiedById = loginDTO.UserId, ModifiedOn = DateTime.UtcNow }, tx, cancellationToken: ct) .ConfigureAwait(false); public async Task UpdateConsumed( int partAllocationId, decimal quantity, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) => await _QueryExecutor .ExecuteAsync(loginDTO, PartAllocationQB.UPDATE_CONSUMED, new { PartAllocationId = partAllocationId, Quantity = quantity, ModifiedById = loginDTO.UserId, ModifiedOn = DateTime.UtcNow }, tx, cancellationToken: ct) .ConfigureAwait(false); public async Task UpdateReleased( int partAllocationId, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) => await _QueryExecutor .ExecuteAsync(loginDTO, PartAllocationQB.UPDATE_RELEASED, new { PartAllocationId = partAllocationId, ModifiedById = loginDTO.UserId, ModifiedOn = DateTime.UtcNow }, tx, cancellationToken: ct) .ConfigureAwait(false); } }