using GB5Shared.DTO.Framework.AutoNumber; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.Resource.Response; using GB5Shared.Validation; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.Json; using System.Threading.Tasks; using WiDAL.CustomCode.WiSection; using WiDAL.DTOs; namespace WiBLL.WiSection { public class WiSectionBLL : IWiSectionBLL { private readonly IWiSectionDAL _dal; private readonly AutoNumber _autoNumber; private readonly IValidation _validation; public WiSectionBLL(IWiSectionDAL dal, AutoNumber autoNumber, IValidation validation) { _dal = dal; _autoNumber = autoNumber; _validation = validation; } public async Task GetById(int WiSectionId, LoginDTO login, CancellationToken ct) => await _dal.GetById(WiSectionId, login, ct).ConfigureAwait(false); public async Task Save(WiSectionDTO dto, LoginDTO login, CancellationToken ct) { if (dto == null) throw new ArgumentNullException(nameof(dto)); AutoNumberDTO? autoNumberDTO = null; try { bool isNew = dto.WiSectionId == 0; if (isNew) { autoNumberDTO = await _autoNumber.GetNumberAsync(1, "WISECTIONEDITOR", login); dto.WiSectionId = autoNumberDTO.StartNumber; } // ✅ pass isNew to DAL await _dal.Save(dto, isNew, login, ct); return isNew ? $"{SuccessResponse.SaveSuccessCode}" : $"{SuccessResponse.UpdateSuccess}"; } catch { if (autoNumberDTO != null && dto.WiSectionId > 0) { await _autoNumber.RollbackAutoNumber("WISECTIONEDITOR", dto.WiSectionId, login); } throw; } } public async Task GetSelectListWiSection(CriteriaDTO criteriaDTO, LoginDTO login, CancellationToken ct) => await _dal.GetSelectListWiSection(criteriaDTO, login, ct); public async Task DeleteWiSection(int WiSectionId, LoginDTO loginDTO) { try { return await _dal.DeleteWiSection(WiSectionId, loginDTO); } catch (Exception) { throw; } } public async Task> GetSectionFullAsync(CriteriaDTO criteriaDTO,LoginDTO loginDTO) { return await _dal.GetSectionFullAsync(criteriaDTO,loginDTO); } } }