Exemplo n.º 1
0
        public async Task <double> TrolleyCalculator(TrolleyItems items)
        {
            Uri endpointUri = new Uri(_readConfig.ReadBaseUrl() + _readConfig.ReadTrollyCaclulator());

            endpointUri = endpointUri.AddQuery("Token", _readConfig.UserId());
            var requestMessage = new HttpRequestMessage(HttpMethod.Post, endpointUri)
            {
                Content = new StringContent(_serializer.Serialise(items), Encoding.UTF8, "application/json")
            };

            _logger.Information("Sending request to {uri}", endpointUri);
            var response = await _client.SendAsync(requestMessage);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                _logger.Error("Error while sending request to {uri}", endpointUri);
                throw new HttpResponseException(response);
            }
            var contents = await response.Content.ReadAsStringAsync();

            double total;

            double.TryParse(contents, out total);
            return(total);
        }
Exemplo n.º 2
0
        public async Task <List <Product> > GetProductsAsync()
        {
            Uri endpointUri = new Uri(_readConfig.ReadBaseUrl() + _readConfig.ReadProduct());

            endpointUri = endpointUri.AddQuery("Token", _readConfig.UserId());
            var requestMessage = new HttpRequestMessage(HttpMethod.Get, endpointUri);

            _logger.Information("Sending request to {uri}", endpointUri);
            var response = await _client.SendAsync(requestMessage);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                _logger.Error("Product repository exception");
                throw new HttpResponseException(response);
            }
            var contents = await response.Content.ReadAsStringAsync();

            return(_deserializer.Deserialize <List <Product> >(contents));
        }