fix: 门店时段与临时调整跨租户处理
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using TakeoutSaaS.Application.App.Stores;
|
||||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||||
using TakeoutSaaS.Application.App.Stores.Validators;
|
using TakeoutSaaS.Application.App.Stores.Validators;
|
||||||
@@ -17,6 +19,7 @@ namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
|||||||
public sealed class BatchUpdateBusinessHoursCommandHandler(
|
public sealed class BatchUpdateBusinessHoursCommandHandler(
|
||||||
IStoreRepository storeRepository,
|
IStoreRepository storeRepository,
|
||||||
ITenantProvider tenantProvider,
|
ITenantProvider tenantProvider,
|
||||||
|
IHttpContextAccessor httpContextAccessor,
|
||||||
ILogger<BatchUpdateBusinessHoursCommandHandler> logger)
|
ILogger<BatchUpdateBusinessHoursCommandHandler> logger)
|
||||||
: IRequestHandler<BatchUpdateBusinessHoursCommand, IReadOnlyList<StoreBusinessHourDto>>
|
: IRequestHandler<BatchUpdateBusinessHoursCommand, IReadOnlyList<StoreBusinessHourDto>>
|
||||||
{
|
{
|
||||||
@@ -24,12 +27,14 @@ public sealed class BatchUpdateBusinessHoursCommandHandler(
|
|||||||
public async Task<IReadOnlyList<StoreBusinessHourDto>> Handle(BatchUpdateBusinessHoursCommand request, CancellationToken cancellationToken)
|
public async Task<IReadOnlyList<StoreBusinessHourDto>> Handle(BatchUpdateBusinessHoursCommand request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// 1. 校验门店存在
|
// 1. 校验门店存在
|
||||||
var tenantId = tenantProvider.GetCurrentTenantId();
|
var ignoreTenantFilter = StoreTenantAccess.ShouldIgnoreTenantFilter(httpContextAccessor);
|
||||||
|
var tenantId = ignoreTenantFilter ? 0 : tenantProvider.GetCurrentTenantId();
|
||||||
var store = await storeRepository.FindByIdAsync(request.StoreId, tenantId, cancellationToken);
|
var store = await storeRepository.FindByIdAsync(request.StoreId, tenantId, cancellationToken);
|
||||||
if (store is null)
|
if (store is null)
|
||||||
{
|
{
|
||||||
throw new BusinessException(ErrorCodes.NotFound, "门店不存在");
|
throw new BusinessException(ErrorCodes.NotFound, "门店不存在");
|
||||||
}
|
}
|
||||||
|
var storeTenantId = store.TenantId;
|
||||||
|
|
||||||
// 2. (空行后) 校验时段重叠
|
// 2. (空行后) 校验时段重叠
|
||||||
var overlapError = BusinessHourValidators.ValidateOverlap(request.Items);
|
var overlapError = BusinessHourValidators.ValidateOverlap(request.Items);
|
||||||
@@ -39,10 +44,10 @@ public sealed class BatchUpdateBusinessHoursCommandHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. (空行后) 删除旧时段
|
// 3. (空行后) 删除旧时段
|
||||||
var existingHours = await storeRepository.GetBusinessHoursAsync(request.StoreId, tenantId, cancellationToken);
|
var existingHours = await storeRepository.GetBusinessHoursAsync(request.StoreId, storeTenantId, cancellationToken);
|
||||||
foreach (var hour in existingHours)
|
foreach (var hour in existingHours)
|
||||||
{
|
{
|
||||||
await storeRepository.DeleteBusinessHourAsync(hour.Id, tenantId, cancellationToken);
|
await storeRepository.DeleteBusinessHourAsync(hour.Id, storeTenantId, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. (空行后) 新增时段配置
|
// 4. (空行后) 新增时段配置
|
||||||
@@ -50,6 +55,7 @@ public sealed class BatchUpdateBusinessHoursCommandHandler(
|
|||||||
{
|
{
|
||||||
var hours = request.Items.Select(item => new StoreBusinessHour
|
var hours = request.Items.Select(item => new StoreBusinessHour
|
||||||
{
|
{
|
||||||
|
TenantId = storeTenantId,
|
||||||
StoreId = request.StoreId,
|
StoreId = request.StoreId,
|
||||||
DayOfWeek = item.DayOfWeek,
|
DayOfWeek = item.DayOfWeek,
|
||||||
HourType = item.HourType,
|
HourType = item.HourType,
|
||||||
@@ -66,7 +72,7 @@ public sealed class BatchUpdateBusinessHoursCommandHandler(
|
|||||||
await storeRepository.SaveChangesAsync(cancellationToken);
|
await storeRepository.SaveChangesAsync(cancellationToken);
|
||||||
logger.LogInformation("批量更新门店营业时段 {StoreId}", request.StoreId);
|
logger.LogInformation("批量更新门店营业时段 {StoreId}", request.StoreId);
|
||||||
|
|
||||||
var refreshed = await storeRepository.GetBusinessHoursAsync(request.StoreId, tenantId, cancellationToken);
|
var refreshed = await storeRepository.GetBusinessHoursAsync(request.StoreId, storeTenantId, cancellationToken);
|
||||||
return refreshed.Select(StoreMapping.ToDto).ToList();
|
return refreshed.Select(StoreMapping.ToDto).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using TakeoutSaaS.Application.App.Stores;
|
||||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||||
using TakeoutSaaS.Domain.Stores.Entities;
|
using TakeoutSaaS.Domain.Stores.Entities;
|
||||||
@@ -17,30 +19,35 @@ namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
|||||||
public sealed class CreateStoreHolidayCommandHandler(
|
public sealed class CreateStoreHolidayCommandHandler(
|
||||||
IStoreRepository storeRepository,
|
IStoreRepository storeRepository,
|
||||||
ITenantProvider tenantProvider,
|
ITenantProvider tenantProvider,
|
||||||
|
IHttpContextAccessor httpContextAccessor,
|
||||||
ILogger<CreateStoreHolidayCommandHandler> logger)
|
ILogger<CreateStoreHolidayCommandHandler> logger)
|
||||||
: IRequestHandler<CreateStoreHolidayCommand, StoreHolidayDto>
|
: IRequestHandler<CreateStoreHolidayCommand, StoreHolidayDto>
|
||||||
{
|
{
|
||||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor = httpContextAccessor;
|
||||||
private readonly ILogger<CreateStoreHolidayCommandHandler> _logger = logger;
|
private readonly ILogger<CreateStoreHolidayCommandHandler> _logger = logger;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<StoreHolidayDto> Handle(CreateStoreHolidayCommand request, CancellationToken cancellationToken)
|
public async Task<StoreHolidayDto> Handle(CreateStoreHolidayCommand request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// 1. 校验门店存在
|
// 1. 校验门店存在
|
||||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
var ignoreTenantFilter = StoreTenantAccess.ShouldIgnoreTenantFilter(_httpContextAccessor);
|
||||||
|
var tenantId = ignoreTenantFilter ? 0 : _tenantProvider.GetCurrentTenantId();
|
||||||
var store = await _storeRepository.FindByIdAsync(request.StoreId, tenantId, cancellationToken);
|
var store = await _storeRepository.FindByIdAsync(request.StoreId, tenantId, cancellationToken);
|
||||||
if (store is null)
|
if (store is null)
|
||||||
{
|
{
|
||||||
throw new BusinessException(ErrorCodes.NotFound, "门店不存在");
|
throw new BusinessException(ErrorCodes.NotFound, "门店不存在");
|
||||||
}
|
}
|
||||||
|
var storeTenantId = store.TenantId;
|
||||||
|
|
||||||
// 2. 构建实体
|
// 2. 构建实体
|
||||||
var holiday = new StoreHoliday
|
var holiday = new StoreHoliday
|
||||||
{
|
{
|
||||||
|
TenantId = storeTenantId,
|
||||||
StoreId = request.StoreId,
|
StoreId = request.StoreId,
|
||||||
Date = request.Date,
|
Date = NormalizeToUtc(request.Date),
|
||||||
EndDate = request.EndDate,
|
EndDate = request.EndDate.HasValue ? NormalizeToUtc(request.EndDate.Value) : null,
|
||||||
IsAllDay = request.IsAllDay,
|
IsAllDay = request.IsAllDay,
|
||||||
StartTime = request.StartTime,
|
StartTime = request.StartTime,
|
||||||
EndTime = request.EndTime,
|
EndTime = request.EndTime,
|
||||||
@@ -57,4 +64,14 @@ public sealed class CreateStoreHolidayCommandHandler(
|
|||||||
// 4. 返回 DTO
|
// 4. 返回 DTO
|
||||||
return StoreMapping.ToDto(holiday);
|
return StoreMapping.ToDto(holiday);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static DateTime NormalizeToUtc(DateTime value)
|
||||||
|
{
|
||||||
|
return value.Kind switch
|
||||||
|
{
|
||||||
|
DateTimeKind.Utc => value,
|
||||||
|
DateTimeKind.Local => value.ToUniversalTime(),
|
||||||
|
_ => DateTime.SpecifyKind(value, DateTimeKind.Utc)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using TakeoutSaaS.Application.App.Stores;
|
||||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||||
using TakeoutSaaS.Domain.Stores.Repositories;
|
using TakeoutSaaS.Domain.Stores.Repositories;
|
||||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||||
@@ -12,18 +14,21 @@ namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
|||||||
public sealed class DeleteStoreHolidayCommandHandler(
|
public sealed class DeleteStoreHolidayCommandHandler(
|
||||||
IStoreRepository storeRepository,
|
IStoreRepository storeRepository,
|
||||||
ITenantProvider tenantProvider,
|
ITenantProvider tenantProvider,
|
||||||
|
IHttpContextAccessor httpContextAccessor,
|
||||||
ILogger<DeleteStoreHolidayCommandHandler> logger)
|
ILogger<DeleteStoreHolidayCommandHandler> logger)
|
||||||
: IRequestHandler<DeleteStoreHolidayCommand, bool>
|
: IRequestHandler<DeleteStoreHolidayCommand, bool>
|
||||||
{
|
{
|
||||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor = httpContextAccessor;
|
||||||
private readonly ILogger<DeleteStoreHolidayCommandHandler> _logger = logger;
|
private readonly ILogger<DeleteStoreHolidayCommandHandler> _logger = logger;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<bool> Handle(DeleteStoreHolidayCommand request, CancellationToken cancellationToken)
|
public async Task<bool> Handle(DeleteStoreHolidayCommand request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// 1. 读取配置
|
// 1. 读取配置
|
||||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
var ignoreTenantFilter = StoreTenantAccess.ShouldIgnoreTenantFilter(_httpContextAccessor);
|
||||||
|
var tenantId = ignoreTenantFilter ? 0 : _tenantProvider.GetCurrentTenantId();
|
||||||
var existing = await _storeRepository.FindHolidayByIdAsync(request.HolidayId, tenantId, cancellationToken);
|
var existing = await _storeRepository.FindHolidayByIdAsync(request.HolidayId, tenantId, cancellationToken);
|
||||||
if (existing is null)
|
if (existing is null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using TakeoutSaaS.Application.App.Stores;
|
||||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||||
using TakeoutSaaS.Application.App.Stores.Queries;
|
using TakeoutSaaS.Application.App.Stores.Queries;
|
||||||
using TakeoutSaaS.Domain.Stores.Repositories;
|
using TakeoutSaaS.Domain.Stores.Repositories;
|
||||||
@@ -12,17 +14,20 @@ namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ListStoreHolidaysQueryHandler(
|
public sealed class ListStoreHolidaysQueryHandler(
|
||||||
IStoreRepository storeRepository,
|
IStoreRepository storeRepository,
|
||||||
ITenantProvider tenantProvider)
|
ITenantProvider tenantProvider,
|
||||||
|
IHttpContextAccessor httpContextAccessor)
|
||||||
: IRequestHandler<ListStoreHolidaysQuery, IReadOnlyList<StoreHolidayDto>>
|
: IRequestHandler<ListStoreHolidaysQuery, IReadOnlyList<StoreHolidayDto>>
|
||||||
{
|
{
|
||||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor = httpContextAccessor;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<IReadOnlyList<StoreHolidayDto>> Handle(ListStoreHolidaysQuery request, CancellationToken cancellationToken)
|
public async Task<IReadOnlyList<StoreHolidayDto>> Handle(ListStoreHolidaysQuery request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// 1. 查询节假日
|
// 1. 查询节假日
|
||||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
var ignoreTenantFilter = StoreTenantAccess.ShouldIgnoreTenantFilter(_httpContextAccessor);
|
||||||
|
var tenantId = ignoreTenantFilter ? 0 : _tenantProvider.GetCurrentTenantId();
|
||||||
var holidays = await _storeRepository.GetHolidaysAsync(request.StoreId, tenantId, cancellationToken);
|
var holidays = await _storeRepository.GetHolidaysAsync(request.StoreId, tenantId, cancellationToken);
|
||||||
|
|
||||||
// 2. 映射 DTO
|
// 2. 映射 DTO
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using TakeoutSaaS.Application.App.Stores;
|
||||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||||
using TakeoutSaaS.Domain.Stores.Entities;
|
using TakeoutSaaS.Domain.Stores.Entities;
|
||||||
@@ -17,18 +19,21 @@ namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
|||||||
public sealed class UpdateStoreHolidayCommandHandler(
|
public sealed class UpdateStoreHolidayCommandHandler(
|
||||||
IStoreRepository storeRepository,
|
IStoreRepository storeRepository,
|
||||||
ITenantProvider tenantProvider,
|
ITenantProvider tenantProvider,
|
||||||
|
IHttpContextAccessor httpContextAccessor,
|
||||||
ILogger<UpdateStoreHolidayCommandHandler> logger)
|
ILogger<UpdateStoreHolidayCommandHandler> logger)
|
||||||
: IRequestHandler<UpdateStoreHolidayCommand, StoreHolidayDto?>
|
: IRequestHandler<UpdateStoreHolidayCommand, StoreHolidayDto?>
|
||||||
{
|
{
|
||||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor = httpContextAccessor;
|
||||||
private readonly ILogger<UpdateStoreHolidayCommandHandler> _logger = logger;
|
private readonly ILogger<UpdateStoreHolidayCommandHandler> _logger = logger;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<StoreHolidayDto?> Handle(UpdateStoreHolidayCommand request, CancellationToken cancellationToken)
|
public async Task<StoreHolidayDto?> Handle(UpdateStoreHolidayCommand request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// 1. 读取配置
|
// 1. 读取配置
|
||||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
var ignoreTenantFilter = StoreTenantAccess.ShouldIgnoreTenantFilter(_httpContextAccessor);
|
||||||
|
var tenantId = ignoreTenantFilter ? 0 : _tenantProvider.GetCurrentTenantId();
|
||||||
var existing = await _storeRepository.FindHolidayByIdAsync(request.HolidayId, tenantId, cancellationToken);
|
var existing = await _storeRepository.FindHolidayByIdAsync(request.HolidayId, tenantId, cancellationToken);
|
||||||
if (existing is null)
|
if (existing is null)
|
||||||
{
|
{
|
||||||
@@ -42,8 +47,8 @@ public sealed class UpdateStoreHolidayCommandHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. 更新字段
|
// 3. 更新字段
|
||||||
existing.Date = request.Date;
|
existing.Date = NormalizeToUtc(request.Date);
|
||||||
existing.EndDate = request.EndDate;
|
existing.EndDate = request.EndDate.HasValue ? NormalizeToUtc(request.EndDate.Value) : null;
|
||||||
existing.IsAllDay = request.IsAllDay;
|
existing.IsAllDay = request.IsAllDay;
|
||||||
existing.StartTime = request.StartTime;
|
existing.StartTime = request.StartTime;
|
||||||
existing.EndTime = request.EndTime;
|
existing.EndTime = request.EndTime;
|
||||||
@@ -59,4 +64,14 @@ public sealed class UpdateStoreHolidayCommandHandler(
|
|||||||
// 5. 返回 DTO
|
// 5. 返回 DTO
|
||||||
return StoreMapping.ToDto(existing);
|
return StoreMapping.ToDto(existing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static DateTime NormalizeToUtc(DateTime value)
|
||||||
|
{
|
||||||
|
return value.Kind switch
|
||||||
|
{
|
||||||
|
DateTimeKind.Utc => value,
|
||||||
|
DateTimeKind.Local => value.ToUniversalTime(),
|
||||||
|
_ => DateTime.SpecifyKind(value, DateTimeKind.Utc)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -337,9 +337,19 @@ public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepos
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<IReadOnlyList<StoreHoliday>> GetHolidaysAsync(long storeId, long tenantId, CancellationToken cancellationToken = default)
|
public async Task<IReadOnlyList<StoreHoliday>> GetHolidaysAsync(long storeId, long tenantId, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var holidays = await context.StoreHolidays
|
var query = context.StoreHolidays.AsNoTracking();
|
||||||
.AsNoTracking()
|
if (tenantId <= 0)
|
||||||
.Where(x => x.TenantId == tenantId && x.StoreId == storeId)
|
{
|
||||||
|
query = query.IgnoreQueryFilters()
|
||||||
|
.Where(x => x.DeletedAt == null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.TenantId == tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
var holidays = await query
|
||||||
|
.Where(x => x.StoreId == storeId)
|
||||||
.OrderBy(x => x.Date)
|
.OrderBy(x => x.Date)
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
@@ -349,8 +359,19 @@ public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepos
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<StoreHoliday?> FindHolidayByIdAsync(long holidayId, long tenantId, CancellationToken cancellationToken = default)
|
public Task<StoreHoliday?> FindHolidayByIdAsync(long holidayId, long tenantId, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return context.StoreHolidays
|
var query = context.StoreHolidays.AsQueryable();
|
||||||
.Where(x => x.TenantId == tenantId && x.Id == holidayId)
|
if (tenantId <= 0)
|
||||||
|
{
|
||||||
|
query = query.IgnoreQueryFilters()
|
||||||
|
.Where(x => x.DeletedAt == null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.TenantId == tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query
|
||||||
|
.Where(x => x.Id == holidayId)
|
||||||
.FirstOrDefaultAsync(cancellationToken);
|
.FirstOrDefaultAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -607,8 +628,19 @@ public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepos
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task DeleteHolidayAsync(long holidayId, long tenantId, CancellationToken cancellationToken = default)
|
public async Task DeleteHolidayAsync(long holidayId, long tenantId, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var existing = await context.StoreHolidays
|
var query = context.StoreHolidays.AsQueryable();
|
||||||
.Where(x => x.TenantId == tenantId && x.Id == holidayId)
|
if (tenantId <= 0)
|
||||||
|
{
|
||||||
|
query = query.IgnoreQueryFilters()
|
||||||
|
.Where(x => x.DeletedAt == null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
query = query.Where(x => x.TenantId == tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
var existing = await query
|
||||||
|
.Where(x => x.Id == holidayId)
|
||||||
.FirstOrDefaultAsync(cancellationToken);
|
.FirstOrDefaultAsync(cancellationToken);
|
||||||
|
|
||||||
if (existing != null)
|
if (existing != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user