コード例 #1
0
        //POST
        public async Task <CampaignBsDTO> AddNewCampaign(CampaignBsDTO newCampaign)
        {
            try
            {
                HttpClient  campaignMS       = new HttpClient();
                String      newCampignString = JsonConvert.SerializeObject(newCampaign);
                HttpContent newCampaignHTTP  = new StringContent(newCampignString, Encoding.UTF8, "application/json");

                string msPath = _configuration.GetSection("Microservices").GetSection("Campaigns").Value;
                HttpResponseMessage response = await campaignMS.PostAsync($"{msPath}/api/campaigns", newCampaignHTTP);

                int statusCode = (int)response.StatusCode;
                if (statusCode == 200)
                {
                    String jsonResponse = await response.Content.ReadAsStringAsync();

                    CampaignBsDTO campaigns = JsonConvert.DeserializeObject <CampaignBsDTO>(jsonResponse);
                    Log.Logger.Information("Succesfull");
                    return(campaigns);
                }
                else
                {
                    Log.Logger.Information("BS throws the error: " + statusCode);
                    throw new BackingServiceException("BS throws the error: " + statusCode);
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Information("Connection with Campaigns is not working: " + ex.Message);
                throw new BackingServiceException("Connection with Campaigns is not working: " + ex.Message);
            }
        }
コード例 #2
0
        //GET-ACTIVE
        public async Task <CampaignBsDTO> GetCampaignActive()
        {
            try
            {
                HttpClient campaignMS = new HttpClient();

                string msPath = _configuration.GetSection("Microservices").GetSection("Campaigns").Value;
                HttpResponseMessage response = await campaignMS.GetAsync($"{msPath}/api/campaigns/active");

                int statusCode = (int)response.StatusCode;
                if (statusCode == 200)
                {
                    String jsonResponse = await response.Content.ReadAsStringAsync();

                    CampaignBsDTO campaigns = JsonConvert.DeserializeObject <CampaignBsDTO>(jsonResponse);
                    Log.Logger.Information("Succesfull");
                    return(campaigns);
                }
                else
                {
                    Log.Logger.Information("BS throws the error: " + statusCode);
                    throw new BackingServiceException("BS throws the error: " + statusCode);
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Information("Connection with Campaigns is not working: " + ex.Message);
                throw new BackingServiceException("Connection with Campaigns is not working: " + ex.Message);
            }
        }