From b426909d3619b27589aff0f1771c198b13262435 Mon Sep 17 00:00:00 2001 From: Dmytro Hridin Date: Thu, 20 Aug 2020 16:25:04 +0300 Subject: [PATCH] CatalogService: Fix issue with Status set when items list is empty (#1304) * Fix issue with Status set when items list is empty * Change method Count() call to Count property Co-authored-by: Dmytro Hridin --- .../Catalog/Catalog.API/Grpc/CatalogService.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs b/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs index 13c7c8d2e..ef22b5be2 100644 --- a/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs +++ b/src/Services/Catalog/Catalog.API/Grpc/CatalogService.cs @@ -68,11 +68,10 @@ namespace Catalog.API.Grpc { var items = await GetItemsByIdsAsync(request.Ids); - if (!items.Any()) - { - context.Status = new Status(StatusCode.NotFound, $"ids value invalid. Must be comma-separated list of numbers"); - } - context.Status = new Status(StatusCode.OK, string.Empty); + context.Status = !items.Any() ? + new Status(StatusCode.NotFound, $"ids value invalid. Must be comma-separated list of numbers") : + new Status(StatusCode.OK, string.Empty); + return this.MapToResponse(items); } @@ -104,7 +103,7 @@ namespace Catalog.API.Grpc private PaginatedItemsResponse MapToResponse(List items) { - return this.MapToResponse(items, items.Count(), 1, items.Count()); + return this.MapToResponse(items, items.Count, 1, items.Count); } private PaginatedItemsResponse MapToResponse(List items, long count, int pageIndex, int pageSize)