예제 #1
0
        //Post
        public async Task <PricingBookBsDTO> AddNew(PricingBookBsDTO newPricingBook)
        {
            try
            {
                String      newPBString = JsonConvert.SerializeObject(newPricingBook);
                HttpContent newPBHTTP   = new StringContent(newPBString, Encoding.UTF8, "application/json");

                HttpResponseMessage response = await productMS.PostAsync($"{msPath}/pricing-books", newPBHTTP);

                int statusCode = (int)response.StatusCode;
                if (statusCode == 200) // OK
                {
                    // Read ASYNC response from HTTPResponse
                    String jsonResponse = await response.Content.ReadAsStringAsync();

                    // Deserialize response
                    PricingBookBsDTO pricing = JsonConvert.DeserializeObject <PricingBookBsDTO>(jsonResponse);
                    Log.Logger.Information("Successfull");
                    return(pricing);
                }
                else
                {
                    Log.Logger.Information("BS throws the error: " + statusCode);
                    // something wrong happens!
                    throw new BackingServiceException("BS throws the error: " + statusCode);
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Information("Connection with Products is not working: " + ex.Message);
                throw new BackingServiceException("Connection with Products is not working: " + ex.Message);
            }
        }
예제 #2
0
        public async Task <PricingBookBsDTO> GetActivePricingBook()
        {
            try
            {
                //HttpContent content = new HttpContent();
                HttpResponseMessage response = await productMS.GetAsync($"{msPath}/pricing-books/active");

                int statusCode = (int)response.StatusCode;
                if (statusCode == 200) // OK
                {
                    // Read ASYNC response from HTTPResponse
                    String jsonResponse = await response.Content.ReadAsStringAsync();

                    Console.WriteLine(jsonResponse);
                    // Deserialize response
                    PricingBookBsDTO pricings = JsonConvert.DeserializeObject <PricingBookBsDTO>(jsonResponse);
                    Log.Logger.Information("Successfull");
                    return(pricings);
                }
                else
                {
                    Log.Logger.Information("BS throws the error: " + statusCode);
                    // something wrong happens!
                    throw new BackingServiceException("BS throws the error: " + statusCode);
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Information("Connection with Products is not working: " + ex.Message);
                throw new BackingServiceException("Connection with Products is not working: " + ex.Message);
            }
        }
        public async Task <List <ProductBsDTO> > GetAllProduct()
        {
            string msPath = _configuration.GetSection("Microservices").GetSection("PricingBooks").Value;

            try
            {
                // Creating HTTP Client
                HttpClient productMS = new HttpClient();

                // Executing an ASYNC HTTP Method could be: Get, Post, Put, Delete
                // In this case is a GET
                // HttpContent content = new
                HttpResponseMessage response = await productMS.GetAsync($"{msPath}/pricing-books/active");

                // HttpResponseMessage response = await productMS.GetAsync($"{msPath}/campaigns/Campaigns-001");
                //HttpResponseMessage response = await productMS.GetAsync($"{msPath}/products");

                int statusCode = (int)response.StatusCode;
                if (statusCode == 200) // OK
                {
                    // Read ASYNC response from HTTPResponse
                    String jsonResponse = await response.Content.ReadAsStringAsync();

                    // Deserialize response
                    PricingBookBsDTO pricingBook = JsonConvert.DeserializeObject <PricingBookBsDTO>(jsonResponse);

                    return(pricingBook.ProductPrices);
                }
                else
                {
                    // something wrong happens!
                    // Add a new Exception for Backing Service
                    throw new BackingServiceException("BS throws the error: " + statusCode);
                }
            }
            catch
            {
                throw new BackingServiceException("Connection with PricingBooks is not working! " + msPath);
            }
        }