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.Threading.Tasks; using WiDAL.CustomCode.WiVersion; using WiDAL.DTOs; namespace WiBLL.WiVersion { public class WiVersionBLL : IWiVersionBLL { private readonly IWiVersionDAL _dal; private readonly AutoNumber _autoNumber; public WiVersionBLL(IWiVersionDAL dal, AutoNumber autoNumber) { _dal = dal; _autoNumber = autoNumber; } public async Task GetById(int LWiVersionId, LoginDTO login, CancellationToken ct) => await _dal.GetById(LWiVersionId, login, ct).ConfigureAwait(false); // WI.LWIVERSION is append-only (see WiVersionQB's header comment) — the only legitimate // writer is WiMasterDAL.TransitionStatusWithSnapshot, which appends a version row and its // matching snapshot in one transaction as part of a real Submit/Approve/Publish/Archive // status change. This standalone save previously let a caller hand-create or hand-edit a // version-history row outside that flow: it never called CLEAR_PREVIOUS_CURRENT (so two // rows could end up ISCURRENT=1), never wrote a matching LWIVERSIONSNAPSHOT row, and // returned the wrong LwiVersionId (an unused AutoNumber reservation instead of the real // IDENTITY value APPEND_VERSION assigns). Refuse outright rather than fix it in place — // there is no legitimate reason to write this table from outside a status transition. public Task Save(WiVersionLogDTO dto, LoginDTO login, CancellationToken ct) => throw new InvalidOperationException( "WI version history is append-only and can only be created via a WI status transition (Submit/Approve/Publish/Archive) — direct save is not supported."); public async Task GetSelectListWiVersion(CriteriaDTO criteriaDTO, LoginDTO login, CancellationToken ct) => await _dal.GetSelectListWiVersion(criteriaDTO, login, ct); // Same reasoning as Save — history rows must never be deleted. public Task DeleteWiVersion(int WiVersionId, LoginDTO loginDTO) => throw new InvalidOperationException("WI version history is append-only and cannot be deleted."); } }