- Die `Delete`-Methode im Controller aktualisiert, um das Löschen nach `id`, `emailAddress` oder `signature` zu unterstützen. - `DeleteByAsync`-Methode im Service hinzugefügt, um Datensätze basierend auf `emailAddress` und `signature` zu löschen. - Fehlerbehandlung mit Protokollierung für fehlgeschlagene Löschversuche verbessert.
40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
using AutoMapper;
|
|
using DigitalData.Core.Application;
|
|
using Microsoft.Extensions.Localization;
|
|
using EnvelopeGenerator.Application.Contracts;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using EnvelopeGenerator.Infrastructure.Contracts;
|
|
using EnvelopeGenerator.Application.Resources;
|
|
using EnvelopeGenerator.Application.DTOs.Receiver;
|
|
using DigitalData.Core.DTO;
|
|
|
|
namespace EnvelopeGenerator.Application.Services
|
|
{
|
|
public class ReceiverService : CRUDService<IReceiverRepository, ReceiverCreateDto, ReceiverReadDto, ReceiverUpdateDto, Receiver, int>, IReceiverService
|
|
{
|
|
public ReceiverService(IReceiverRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper)
|
|
: base(repository, mapper)
|
|
{
|
|
}
|
|
|
|
public async Task<DataResult<ReceiverReadDto>> ReadByAsync(string? emailAddress = null, string? signature = null)
|
|
{
|
|
var rcv = await _repository.ReadByAsync(emailAddress: emailAddress, signature: signature);
|
|
|
|
if (rcv is null)
|
|
return Result.Fail<ReceiverReadDto>();
|
|
|
|
return Result.Success(_mapper.MapOrThrow<ReceiverReadDto>(rcv));
|
|
}
|
|
|
|
public async Task<Result> DeleteByAsync(string? emailAddress = null, string? signature = null)
|
|
{
|
|
var rcv = await _repository.ReadByAsync(emailAddress: emailAddress, signature: signature);
|
|
|
|
if (rcv is null)
|
|
return Result.Fail();
|
|
|
|
return await _repository.DeleteAsync(rcv) ? Result.Success() : Result.Fail();
|
|
}
|
|
}
|
|
} |