Beispiel #1
0
        public static Task <ServiceResult <DeleteWidgetResponseDto> > DeleteWidgetAsync(this IExampleApi service, string id, CancellationToken cancellationToken = default(CancellationToken))
        {
            var request = new DeleteWidgetRequestDto {
                Id = id
            };

            return(service.DeleteWidgetAsync(request, cancellationToken));
        }
        public async Task <ServiceResult <DeleteWidgetResponseDto> > DeleteWidgetAsync(DeleteWidgetRequestDto request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (string.IsNullOrEmpty(request.Id))
            {
                return(ServiceResult.Failure(ExampleApiErrors.CreateInvalidRequestMissingWidgetId()));
            }

            bool wasDeleted = await m_repository.TryDeleteWidgetAsync(request.Id, cancellationToken).ConfigureAwait(false);

            if (!wasDeleted)
            {
                return(ServiceResult.Failure(ExampleApiErrors.CreateNotFoundWidget(request.Id)));
            }

            return(ServiceResult.Success(new DeleteWidgetResponseDto()));
        }