using Fake.DependencyInjection; using Oms.Domain.ChannelsAggregate.Entities; using Oms.Domain.ChannelsAggregate.Repositories; using Oms.SqlSugarCore.Repositories; namespace Oms.SqlSugarCore.Channels; public class IssueTemplateRepository : OmsSqlSugarRepository, IIssueTemplateRepository, IScopedDependency { public async Task ExistsDuplicateAsync( string? organizationId, string issueType, int? excludeId = null, CancellationToken cancellationToken = default) { var normalizedOrg = string.IsNullOrWhiteSpace(organizationId) ? null : organizationId.Trim(); var normalizedType = issueType.Trim(); var hasExcludeId = excludeId.HasValue; var excludeIdValue = excludeId.GetValueOrDefault(); if (normalizedOrg == null) { return await AnyAsync( x => x.IssueType == normalizedType && (x.OrganizationId == null || x.OrganizationId == string.Empty) && (!hasExcludeId || x.Id != excludeIdValue), cancellationToken); } return await AnyAsync( x => x.IssueType == normalizedType && x.OrganizationId == normalizedOrg && (!hasExcludeId || x.Id != excludeIdValue), cancellationToken); } }