using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using CRMSalesDAL.DTO.LeadScoring; using CRMSalesDAL.Query.LeadScoring; namespace CRMSalesDAL.CustomCode.LeadScoring; public class LeadScoringDAL : ILeadScoringDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public LeadScoringDAL(IQueryExecutor queryExecutor, IValidation validation) { _QueryExecutor = queryExecutor; _Validation = validation; } public async Task GetLeadScoringInput(int leadId, LoginDTO loginDTO, CancellationToken ct) { try { // QuerySingleAsync wraps Dapper's QuerySingleOrDefaultAsync — returns null if LeadId // does not exist (same precedent as BusinessAspirationGoalDAL.GetLatestBusinessAspirationGoal). return await _QueryExecutor .QuerySingleAsync(loginDTO, LeadScoringQB.GET_LEAD_SCORING_INPUT, new { LeadId = leadId }, cancellationToken: ct) .ConfigureAwait(false); } catch { throw; } } public async Task UpdateLeadScore(int leadId, int score, LoginDTO loginDTO, CancellationToken ct) { try { return await _QueryExecutor .ExecuteAsync(loginDTO, LeadScoringQB.UPDATE_LEAD_SCORE, new { LeadId = leadId, Score = score }, cancellationToken: ct) .ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.UpdateErrorMessage); throw new Exception(error); } } }