using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Threading.Tasks;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.QueryExecutor;
using GoodBooks.PAY.PAYDAL.DTO.Loyalty;
using GoodBooks.PAY.PAYDAL.Query.Loyalty;
namespace GoodBooks.PAY.PAYDAL.CustomCode.Loyalty
{
///
/// DAL implementation for MLOYALTYTIER.
///
public class LoyaltyTierDAL : ILoyaltyTierDAL
{
private readonly IQueryExecutor _queryExecutor;
public LoyaltyTierDAL(IQueryExecutor queryExecutor)
{
_queryExecutor = queryExecutor;
}
///
public async Task> GetTiersByProgram(int programId, LoginDTO login)
{
try
{
IEnumerable tiers = await _queryExecutor.QueryAsync(
login,
LoyaltyTierQB.GET_TIERS_BY_PROGRAM,
new { LoyaltyProgramId = programId }).ConfigureAwait(false);
return tiers ?? Array.Empty();
}
catch (Exception)
{
throw;
}
}
///
public async Task InsertLoyaltyTier(LoyaltyTierDTO dto, LoginDTO login, DbTransaction? tx)
{
try
{
int rows = await _queryExecutor.ExecuteAsync(
login,
LoyaltyTierQB.INSERT_LOYALTY_TIER,
new
{
dto.LoyaltyTierId,
dto.LoyaltyProgramId,
dto.SlNo,
dto.TierCode,
dto.TierName,
dto.MinPoints,
dto.MaxPoints,
dto.EarnMultiplier,
dto.Remarks
},
tx).ConfigureAwait(false);
return rows;
}
catch (Exception)
{
throw;
}
}
///
public async Task GetTierForPoints(int programId, decimal lifetimePoints, LoginDTO login)
{
try
{
LoyaltyTierDTO? tier = await _queryExecutor.QuerySingleAsync(
login,
LoyaltyTierQB.GET_TIER_FOR_POINTS,
new
{
LoyaltyProgramId = programId,
LifetimePoints = lifetimePoints
}).ConfigureAwait(false);
return tier;
}
catch (Exception)
{
throw;
}
}
}
}