using FMDAL.DTO.AssetLedger; using FMDAL.Query.AssetLedger; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace FMDAL.CustomCode.AssetLedger { public class AssetLedgerDAL : IAssetLedgerDAL { private readonly IQueryExecutor _qe; public AssetLedgerDAL(IQueryExecutor qe) => _qe = qe; public async Task GetAssetLedger(int assetLedgerId, LoginDTO login, CancellationToken ct) { var items = await _qe.QueryAsync(login, AssetLedgerQB.GET_ASSETLEDGER, new { AssetLedgerId = assetLedgerId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); return items.FirstOrDefault(); } public async Task> GetAssetLedgerListByAsset(int assetId, LoginDTO login, CancellationToken ct) { return await _qe.QueryAsync(login, AssetLedgerQB.GET_ASSETLEDGER_LIST_BY_ASSET, new { AssetId = assetId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); } public async Task> GetAssetLedgerListByReference(string referenceType, int referenceId, LoginDTO login, CancellationToken ct) { return await _qe.QueryAsync(login, AssetLedgerQB.GET_ASSETLEDGER_LIST_BY_REFERENCE, new { ReferenceType = referenceType, ReferenceId = referenceId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); } public async Task SaveAssetLedger(AssetLedgerDTO dto, LoginDTO login, DbTransaction tx, CancellationToken ct) { dto.TenantId = login.ClientId; dto.CreatedOn = DateTime.UtcNow; dto.CreatedById = login.UserId; dto.EventTime = DateTime.UtcNow; await _qe.ExecuteAsync(login, AssetLedgerQB.SAVE_ASSETLEDGER, dto, tx, cancellationToken: ct).ConfigureAwait(false); } public async Task VoidAssetLedger(int assetLedgerId, LoginDTO login, DbTransaction tx, CancellationToken ct) { await _qe.ExecuteAsync(login, AssetLedgerQB.VOID_ASSETLEDGER, new { AssetLedgerId = assetLedgerId, TenantId = login.ClientId }, tx, cancellationToken: ct).ConfigureAwait(false); } } }