コード例 #1
0
        private static StringContent StringContent(OrderProcessingDto cancellationDto)
        {
            var serialized = JsonConvert.SerializeObject(cancellationDto, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });
            var content = new StringContent(serialized, System.Text.Encoding.UTF8, "application/json");

            return(content);
        }
コード例 #2
0
        public async Task <ApiResponse> Execute(OrderProcessingDto cancellationDto, CancellationToken cancellationToken)
        {
            var uri = new Uri($"{_baseUrl}{Path}");

            var content = StringContent(cancellationDto);

            var result = await _client.PostAsync(uri, content, cancellationToken);

            return(new ApiResponse(
                       result.IsSuccessStatusCode,
                       result.Content is null
                    ? null
                    : await result.Content.ReadAsStringAsync()));
        }
コード例 #3
0
        public async Task <ProcessedResult> TryToProcess(Order order, CancellationToken cancellationToken)
        {
            if (_isTest)
            {
                return(ProcessedResult.Executed);
            }

            var cancellationDto = new OrderProcessingDto
            {
                Products     = order.Products.Select(p => new ProductDto(p.ItemId, p.Price, p.Quantity)).ToArray(),
                Description  = order.OrderDescription,
                ComponentIds = order.Components.Select(x => x.Id).ToArray(),
                CheckNumber  = order.CheckNumber,
                OrderNumber  = order.OrderNumber,
                Amount       = order.Amount
            };

            var result = await _client.Execute(cancellationDto, cancellationToken);

            return(result.IsSuccess
                ? ProcessedResult.Executed
                : ProcessedResult.Failed);
        }