protected override async Task <IResponseContainerWithValue <TDto> > GetResultAsync(GetIntIdEntityCommand <TEntity, TDto> command) { if (command.DtoFactory is null) { throw new ArgumentException($"DTO factory property is not assigned."); } IResponseContainerWithValue <TDto> result; var(request, dtoFactory) = command; var entity = await genericRepository.GetAsync(request.Id); if (entity is null) { result = new ResponseContainerWithValue <TDto>(); result.AddErrorMessage($"{typeof(TEntity).Name} with ID={request.Id} is not found."); Log.Error(result.Messages); } else { result = new ResponseContainerWithValue <TDto> { Value = dtoFactory(entity) } }; return(result); } }
public async Task <ActionResult> Get([FromRoute] GetGroupRequest request) { var command = new GetIntIdEntityCommand <Group, GroupDto>() { DtoFactory = GroupDto.From, Request = request }; var result = await getIntIdEntityHandler.HandleAsync(command); if (!result.IsSuccess) { ModelState.AddModelError(Constants.ModelState.ErrorsProperty, result.Messages); return(BadRequest(ModelState)); } return(Ok(result.Value)); }