예제 #1
0
        public async Task <ScholarshipItem> GetScholarshipItemAsync(int id)
        {
            var request = new ScholarshipItemRequest {
                Id = id
            };
            var response = await _client.GetItemByIdAsync(request);

            return(MapToScholarshipItemResponse(response));
        }
예제 #2
0
        public override async Task <ScholarshipItemResponse> GetItemById(ScholarshipItemRequest request, ServerCallContext context)
        {
            _logger.LogInformation("Begin grpc call ScholarshipService.GetItemById for product id {Id}", request.Id);
            if (request.Id <= 0)
            {
                context.Status = new Status(StatusCode.FailedPrecondition, $"Id must be > 0 (received {request.Id})");
                return(null);
            }

            var item = await _scholarshipContext.ScholarshipItems.SingleOrDefaultAsync(ci => ci.Id == request.Id);

            var baseUri             = _settings.PicBaseUrl;
            var azureStorageEnabled = _settings.AzureStorageEnabled;

            item.FillScholarshipItemUrl(baseUri, azureStorageEnabled: azureStorageEnabled);

            if (item != null)
            {
                return(new ScholarshipItemResponse()
                {
                    AvailableSlots = item.AvailableSlots,
                    Description = item.Description,
                    Id = item.Id,
                    MaxSlotsThreshold = item.MaxSlotThreshold,
                    Name = item.Name,
                    OnReapply = item.OnReapply,
                    PictureFileName = item.PictureFileName,
                    PictureUri = item.PictureUri,
                    Amount = (double)item.Amount,
                    ReslotThreshold = item.ReslotThreshold
                });
            }

            context.Status = new Status(StatusCode.NotFound, $"ScholarshipItem with id {request.Id} do not exist");
            return(null);
        }