Updated namespaces to align with the new DigitalData.Core structure, replacing `DigitalData.Core.Abstractions` with `DigitalData.Core.Application.Interfaces` and `DigitalData.Core.Client.Interface`. Removed the `IUnique<int>` interface from several DTOs, simplifying their design and altering the handling of entity identification. Updated project files to reflect new dependency versions for improved compatibility and features. Cleaned up using directives to remove obsolete references, enhancing code maintainability.
50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using AutoMapper;
|
|
using DigitalData.Core.Application;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using EnvelopeGenerator.Application.Contracts.Repositories;
|
|
using EnvelopeGenerator.Application.DTOs.Receiver;
|
|
using DigitalData.Core.DTO;
|
|
using Microsoft.Extensions.Logging;
|
|
using EnvelopeGenerator.Application.Contracts.Services;
|
|
|
|
namespace EnvelopeGenerator.Application.Services;
|
|
|
|
public class ReceiverService : CRUDService<IReceiverRepository, ReceiverCreateDto, ReceiverReadDto, Receiver, int>, IReceiverService
|
|
{
|
|
public ReceiverService(IReceiverRepository repository, 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.Map<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();
|
|
}
|
|
|
|
public virtual async Task<Result> UpdateAsync<TUpdateDto>(TUpdateDto updateDto)
|
|
{
|
|
var val = await _repository.ReadByIdAsync(updateDto.GetId<int>());
|
|
if (val == null)
|
|
{
|
|
return Result.Fail().Notice(LogLevel.Warning, Flag.NotFound, $"{updateDto.GetIdOrDefault<int>()} is not found in update process of {GetType()} entity.");
|
|
}
|
|
|
|
var entity = _mapper.Map(updateDto, val);
|
|
return (await _repository.UpdateAsync(entity)) ? Result.Success() : Result.Fail();
|
|
}
|
|
} |