public async Task <HttpResponseMessage> PostCustomer(Customer customer) { HttpResponseMessage response; HttpClient httpClient = new HttpClient(); string url = ""; string authToken = ""; string eventbaseurl = ""; if (ConfigurationManager.AppSettings["IsTestingEnv"].ToString() == "true") { url = ConfigurationManager.AppSettings["CutomerAddUrl"].ToString(); authToken = ConfigurationManager.AppSettings["authToken"].ToString(); eventbaseurl = ConfigurationManager.AppSettings["EventApiUrl"].ToString(); } else { url = Environment.GetEnvironmentVariable("CutomerAddUrl").ToString(); authToken = Environment.GetEnvironmentVariable("authToken"); eventbaseurl = Environment.GetEnvironmentVariable("EventApiUrl"); } try { if (Request.Headers.Contains("transactionID")) { customer.TransactionID = Request.Headers.GetValues("transactionID").FirstOrDefault(); } if (Request.Headers.Contains("agentID")) { customer.AgentId = Request.Headers.GetValues("agentID").FirstOrDefault(); } customer.id = GenerateCustomerId.Generate(9); var content = JsonConvert.SerializeObject(customer); var stringContent = new StringContent(content, UnicodeEncoding.UTF8, "application/json"); var result = httpClient.PostAsync(url, stringContent); response = result.Result; if (response.StatusCode == HttpStatusCode.OK) { //HttpClient eventHttpClient = new HttpClient(); //var eventurl= eventbaseurl+"?customerId=" +customer.id; //eventHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken); //var eventresponse=eventHttpClient.GetAsync(eventurl); //eventresponse.Wait(); //response = Request.CreateResponse(HttpStatusCode.OK, "Customer details entered succesfully"); await ServiceBusHandler.Initialize(JsonConvert.SerializeObject(customer)); await CustomerEventRaiser.RaiseNewCustomerEvent(customer.id); } return(response); } catch (Exception ex) { response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex); return(response); } }
public async System.Threading.Tasks.Task <HttpResponseMessage> GetEventAsync(string customerId) { HttpResponseMessage response; try { string id = customerId.Replace("\"", ""); CustomerEventRaiser customerEventRaiser = new CustomerEventRaiser(); await customerEventRaiser.RaiseNewCustomerEvent(id); response = Request.CreateResponse(HttpStatusCode.OK, "new customer " + id + " created using event hub"); } catch (Exception ex) { response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex); } return(response); }