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, IReceiverService { public ReceiverService(IReceiverRepository repository, IMapper mapper) : base(repository, mapper) { } public async Task> ReadByAsync(string? emailAddress = null, string? signature = null) { var rcv = await _repository.ReadByAsync(emailAddress: emailAddress, signature: signature); if (rcv is null) return Result.Fail(); return Result.Success(_mapper.Map(rcv)); } public async Task 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 UpdateAsync(TUpdateDto updateDto) { var val = await _repository.ReadByIdAsync(updateDto.GetId()); if (val == null) { return Result.Fail().Notice(LogLevel.Warning, Flag.NotFound, $"{updateDto.GetIdOrDefault()} is not found in update process of {GetType()} entity."); } var entity = _mapper.Map(updateDto, val); return (await _repository.UpdateAsync(entity)) ? Result.Success() : Result.Fail(); } }