diff --git a/DigitalData.Core.Application/CRUDService.cs b/DigitalData.Core.Application/CRUDService.cs index c4ddd0a..6c7f8fb 100644 --- a/DigitalData.Core.Application/CRUDService.cs +++ b/DigitalData.Core.Application/CRUDService.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.ComponentModel.DataAnnotations; using DigitalData.Core.DTO; using DigitalData.Core.Abstractions; +using Microsoft.Extensions.Logging; namespace DigitalData.Core.Application { @@ -80,9 +81,16 @@ namespace DigitalData.Core.Application /// A service message indicating success or failure. public virtual async Task UpdateAsync(TUpdateDto updateDto) { - var entity = _mapper.MapOrThrow(updateDto); - bool isUpdated = await _repository.UpdateAsync(entity); - return isUpdated ? Result.Success() : Result.Fail(); + var currentEntitiy = await _repository.ReadByIdAsync(updateDto.Id); + + if (currentEntitiy is null) + return Result.Fail().Notice(LogLevel.Warning, Flag.NotFound, $"{updateDto.Id} is not found in update process of {GetType()} entity."); + + var entity = _mapper.Map(updateDto, currentEntitiy); + + return await _repository.UpdateAsync(entity) + ? Result.Success() + : Result.Fail(); } ///