From d49aaf61dca276513430fb18b268fd4426909326 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 20 May 2025 12:44:43 +0200 Subject: [PATCH] Update CreateAsync to return DataResult Modified the CreateAsync method in CRUDService.cs and ICRUDService.cs to change the return type from DataResult to DataResult. The implementation now maps the created entity to a read DTO, providing the caller with the complete entity representation instead of just its ID. --- DigitalData.Core.Application/CRUDService.cs | 5 +++-- DigitalData.Core.Application/Interfaces/ICRUDService.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/DigitalData.Core.Application/CRUDService.cs b/DigitalData.Core.Application/CRUDService.cs index 467d20f..eace01e 100644 --- a/DigitalData.Core.Application/CRUDService.cs +++ b/DigitalData.Core.Application/CRUDService.cs @@ -33,11 +33,12 @@ namespace DigitalData.Core.Application /// /// The DTO to create an entity from. /// A service result indicating success or failure, including the entity DTO. - public virtual async Task> CreateAsync(TCreateDto createDto) + public virtual async Task> CreateAsync(TCreateDto createDto) { var entity = _mapper.Map(createDto); var createdEntity = await _repository.CreateAsync(entity); - return createdEntity is null ? Result.Fail() : Result.Success(createdEntity.GetIdOrDefault()); + var dto = _mapper.Map(createdEntity); + return createdEntity is null ? Result.Fail() : Result.Success(dto); } /// diff --git a/DigitalData.Core.Application/Interfaces/ICRUDService.cs b/DigitalData.Core.Application/Interfaces/ICRUDService.cs index eafcca1..bd9f56f 100644 --- a/DigitalData.Core.Application/Interfaces/ICRUDService.cs +++ b/DigitalData.Core.Application/Interfaces/ICRUDService.cs @@ -12,7 +12,7 @@ namespace DigitalData.Core.Application.Interfaces /// /// The data transfer object containing the information for the new entity. /// A task representing the asynchronous operation, with a containing the identifier of the created entity or an error message. - Task> CreateAsync(TCreateDto createDto); + Task> CreateAsync(TCreateDto createDto); /// /// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage,