30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
using AMREZ.EOP.Abstractions.Applications.Tenancy;
|
|
using AMREZ.EOP.Abstractions.Applications.UseCases.MasterData.Allergen;
|
|
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace AMREZ.EOP.Application.UseCases.MasterData.Allergen;
|
|
|
|
public class DeleteAllergenUseCase : IDeleteAllergenUseCase
|
|
{
|
|
private readonly IAllergenRepository _repo;
|
|
private readonly ITenantResolver _tenantResolver;
|
|
private readonly IHttpContextAccessor _http;
|
|
|
|
public DeleteAllergenUseCase(IAllergenRepository repo, ITenantResolver tr, IHttpContextAccessor http)
|
|
{
|
|
_repo = repo;
|
|
_tenantResolver = tr;
|
|
_http = http;
|
|
}
|
|
|
|
public async Task<bool> ExecuteAsync(Guid id, CancellationToken ct = default)
|
|
{
|
|
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
|
|
var tc = _tenantResolver.Resolve(http) ?? throw new InvalidOperationException("No tenant");
|
|
var tid = Guid.Parse(tc.Id);
|
|
|
|
var n = await _repo.SoftDeleteAsync(id, tid, ct);
|
|
return n > 0;
|
|
}
|
|
} |