39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
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<IssueTemplate>, IIssueTemplateRepository, IScopedDependency
|
|
{
|
|
public async Task<bool> 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);
|
|
}
|
|
}
|