Update CreateAsync to return DataResult<TReadDto>

Modified the CreateAsync method in CRUDService.cs and ICRUDService.cs to change the return type from DataResult<TId> to DataResult<TReadDto>. The implementation now maps the created entity to a read DTO, providing the caller with the complete entity representation instead of just its ID.
This commit is contained in:
Developer 02 2025-05-20 12:44:43 +02:00
parent b95baaef5f
commit d49aaf61dc
2 changed files with 4 additions and 3 deletions

View File

@ -33,11 +33,12 @@ namespace DigitalData.Core.Application
/// </summary>
/// <param name="createDto">The DTO to create an entity from.</param>
/// <returns>A service result indicating success or failure, including the entity DTO.</returns>
public virtual async Task<DataResult<TId>> CreateAsync(TCreateDto createDto)
public virtual async Task<DataResult<TReadDto>> CreateAsync(TCreateDto createDto)
{
var entity = _mapper.Map<TEntity>(createDto);
var createdEntity = await _repository.CreateAsync(entity);
return createdEntity is null ? Result.Fail<TId>() : Result.Success(createdEntity.GetIdOrDefault<TId>());
var dto = _mapper.Map<TReadDto>(createdEntity);
return createdEntity is null ? Result.Fail<TReadDto>() : Result.Success(dto);
}
/// <summary>

View File

@ -12,7 +12,7 @@ namespace DigitalData.Core.Application.Interfaces
/// </summary>
/// <param name="createDto">The data transfer object containing the information for the new entity.</param>
/// <returns>A task representing the asynchronous operation, with a <see cref="DataResult{TId}"/> containing the identifier of the created entity or an error message.</returns>
Task<DataResult<TId>> CreateAsync(TCreateDto createDto);
Task<DataResult<TReadDto>> CreateAsync(TCreateDto createDto);
/// <summary>
/// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage,