using System.Data.Common; using AccountsDAL.DTO.DeferalPlan; using AccountsDAL.Query.AccountGroup; using AccountsDAL.Query.CostCategory; using AccountsDAL.Query.DeferalPlan; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.ResponseStandard; using GB5Shared.Validation; using Newtonsoft.Json; namespace AccountsDAL.CustomCode.DeferalPlan { public class DeferalPlanDAL : IDeferalPlanDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public DeferalPlanDAL(IQueryExecutor queryExecutor, IValidation validation) { _QueryExecutor = queryExecutor; _Validation = validation; } public async Task GetDeferalPlan(int deferralPlanId, LoginDTO loginDTO) { try { var dto = await _QueryExecutor .QuerySingleAsync(loginDTO, DeferalPlanQB.GET_DEFERALPLAN, new { DeferalPlanId = deferralPlanId }) .ConfigureAwait(false); return JsonConvert.SerializeObject(dto); } catch (Exception) { throw; } } public async Task> SaveDeferalPlan(DeferalPlanDTO dto, LoginDTO loginDTO, DbTransaction tx) { try { dto.DeferalPlanCreatedById = loginDTO.UserId; dto.DeferalPlanCreatedOn = DateTime.UtcNow; dto.DeferalPlanModifiedById = loginDTO.UserId; dto.DeferalPlanModifiedOn = DateTime.UtcNow; // dto.TenantId = loginDTO.ClientId; int rows = await _QueryExecutor .ExecuteAsync(loginDTO, DeferalPlanQB.SAVE_DEFERALPLAN, dto, tx) .ConfigureAwait(false); return rows > 0 ? Result.Success("Deferral plan saved successfully.") : Result.Failure("Failed to save deferral plan."); } catch (Exception) { throw; } } public async Task> UpdateDeferalPlan(DeferalPlanDTO dto, LoginDTO loginDTO, DbTransaction tx) { try { dto.DeferalPlanModifiedById = loginDTO.UserId; dto.DeferalPlanModifiedOn = DateTime.UtcNow; // dto.TenantId = loginDTO.ClientId; int rows = await _QueryExecutor .ExecuteAsync(loginDTO, DeferalPlanQB.UPDATE_DEFERALPLAN, dto, tx) .ConfigureAwait(false); return rows > 0 ? Result.Success("Deferral plan updated successfully.") : Result.Failure("Failed to update deferral plan."); } catch (Exception) { throw; } } public async Task> DeleteDeferalPlan(int deferralPlanId, LoginDTO loginDTO, DbTransaction tx) { try { int result = await _QueryExecutor.ExecuteAsync(loginDTO, DeferalPlanQB.DELETE_DEFERALPLAN, new { DeferalPlanId = deferralPlanId }, tx).ConfigureAwait(false); return result > 0 ? Result.Success("Deferral plan deleted successfully.") : Result.Failure("Deferral plan not found or already deleted."); } catch (Exception) { throw; } } public async Task GetSelectListDeferalPlan(CriteriaDTO criteriaDTO, LoginDTO loginDTO) { try { var result = await _QueryExecutor .QueryAsync(loginDTO, DeferalPlanQB.GET_SELECTLIST_DEFERALPLAN).ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch (Exception) { throw; } } } }