using GB5Shared.DTO.Framework.AutoNumber; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.QueryExecutor; using PayRollDAL.CustomeCode.PayGroup; using PayRollDAL.DTO.PayGroup; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PayRollBLL.PayGroup { public class PayGroupBLL : IPayGroupBLL { private readonly IPayGroupDAL _PayGroupDAL; private readonly AutoNumber _AutoNumber; private readonly IQueryExecutor _QueryExecutor; public PayGroupBLL(IPayGroupDAL payGroupDAL, AutoNumber autoNumber, IQueryExecutor queryExecutor) { _PayGroupDAL = payGroupDAL; _AutoNumber = autoNumber; _QueryExecutor = queryExecutor; } public async Task GetSelectListPayGroup( int FirstNumber, int MaxResult, CriteriaDTO criteriaDTO, LoginDTO LoginDTO) { try { return await _PayGroupDAL.GetSelectListPayGroup( FirstNumber, MaxResult, criteriaDTO, LoginDTO); } catch (Exception ex) { throw new Exception("Error in GetSelectListPayGroup", ex); } } // ── Get single record ───────────────────────────────────────────── public async Task GetPayGroup(int PayGroupId, LoginDTO LoginDTO) { return await _PayGroupDAL.GetPayGroup(PayGroupId, LoginDTO).ConfigureAwait(false); } // ── Save (insert or update) ─────────────────────────────────────── public async Task SavePayGroup(PayGroupDTO PayGroupDTO, LoginDTO LoginDTO) { if (PayGroupDTO == null) throw new ArgumentNullException(nameof(PayGroupDTO)); bool isNew = PayGroupDTO.PayGroupId == 0; AutoNumberDTO? autoNumberDTO = null; var trans = await _QueryExecutor.BeginTransactionAsync(LoginDTO).ConfigureAwait(false); try { if (isNew) { autoNumberDTO = await _AutoNumber.GetNumberAsync(1, "PAYGROUP", LoginDTO) .ConfigureAwait(false); PayGroupDTO.PayGroupId = autoNumberDTO.StartNumber; PayGroupDTO.PayGroupCreatedById = LoginDTO.UserId; PayGroupDTO.PayGroupCreatedOn = DateTime.UtcNow; } PayGroupDTO.PayGroupModifiedById = LoginDTO.UserId; PayGroupDTO.PayGroupModifiedOn = DateTime.UtcNow; int rows = isNew ? await _PayGroupDAL.SavePayGroup(PayGroupDTO, LoginDTO, trans).ConfigureAwait(false) : await _PayGroupDAL.UpdatePayGroup(PayGroupDTO, LoginDTO, trans).ConfigureAwait(false); await _QueryExecutor.CommitAsync(trans).ConfigureAwait(false); if (rows <= 0) return isNew ? "Failed to save pay group." : "Failed to update pay group."; return isNew ? $"Details Saved Successfully With Id :{PayGroupDTO.PayGroupId}" : $"Details Updated Successfully With Id :{PayGroupDTO.PayGroupId}"; } catch (Exception) { await _QueryExecutor.RollbackAsync(trans).ConfigureAwait(false); if (autoNumberDTO != null) await _AutoNumber.RollbackAutoNumber("PAYGROUP", autoNumberDTO.StartNumber, LoginDTO) .ConfigureAwait(false); throw; } } // ── Delete ──────────────────────────────────────────────────────── public async Task DeletePayGroup(int PayGroupId, LoginDTO LoginDTO) { return await _PayGroupDAL.DeletePayGroup(PayGroupId, LoginDTO).ConfigureAwait(false); } // ── List ────────────────────────────────────────────────────────── public async Task GetPayGroupList(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { return await _PayGroupDAL.GetPayGroupList(CriteriaDTO, LoginDTO) .ConfigureAwait(false); } catch (Exception) { throw; } } } }