private void CreateAfeCallbackDbLog(int customerId, AFECustomerChangeNotificationResponse afeNotificationResponse)
        {
            LogDbAction("Finally updating the database");
            //Fire and Forget call to AFE Web Api
            //NOTE: read the comments below and take the necessary steps
            //Task.Factory.StartNew(() =>
            //{
            try
            {
                // wether API Success or Fail need to update the database, so windows service will pick up and process(Windows service need to be build)
                _gmdToAfeService.Save(customerId, afeNotificationResponse.Success);
                //Build the request and make a call based on AFE API Requirement
                //use the model 'MciCustomerInfoModel' to build request
                //you may wish to use 'AfeNotificationService' to extract the code from here, (this implimentation not completed)
            }
            // turn our request string into a byte stream
            catch (Exception ex)
            // now send it
            // grab te response and print it out to the console along with the status code
            {
                LogDbAction("Error while executing _gmdToAfeService.Save method--> " + ex.Message);
            }

            LogDbAction("Updated the database");
        }
        public AFECustomerChangeNotificationResponse CustomerChange(AFECustomerChangeNotificationRequest request)
        {
            string postdataJson = null;
            var    retval       = new AFECustomerChangeNotificationResponse();

            try
            {
                postdataJson = JsonConvert.SerializeObject(request);
                //var postdataString = new StringContent(postdataJson, new UTF8Encoding(), "application/json");

                var response = _client.PostAsJsonAsync(_targetActionName, request).Result;
                // This extension handles json serialization of the payload etc...

                retval.Success = response.IsSuccessStatusCode;

                OnCompleted?.Invoke($"{_client.BaseAddress.AbsoluteUri}{_targetActionName}",
                                    response.ToString(), postdataJson);
            }
            catch (Exception ex)
            {
                retval.Success = false;
                OnError?.Invoke($"{_client.BaseAddress.AbsoluteUri}{_targetActionName}", ex, postdataJson);
            }

            return(retval);
        }
        public IHttpActionResult PostCustomer(Models.ParameterModels.CustomerLoadOrMatch customer
                                              )
        {
            var mappedCustomer = Mapper.Map <WebApiServices.Models.Customer.CustomerLoadOrMatch>(customer);
            // customer.AccessControl = _clientScopeService.VerifyUserHasAccessToGroupCode(customer.AccessControl, Scope.CUSTOMER_LOAD);

            int      customerId;
            DateTime processedDatetime;
            var      id = _mciRequestService.SaveCustomer(mappedCustomer, out customerId, out processedDatetime);
            // This is the [RecordID] PKey of the [MCI_CUSTOMER_API_LANDING] table

            string message = (id > 0)
                ? $"Customer loaded successfully. [Id={id}]"
                : $"Customer load failed. [Id={id}]";

            // Callback to Afe WebApi notify of customer change : No async call currently
            //
            //Task.Factory.StartNew(() =>
            //{
            AFECustomerChangeNotificationResponse afeNotificationResponse = NotifyChangeToAfe(customer, processedDatetime, id);

            //};

            // Update local Afe log table to reflect the call above ...
            CreateAfeCallbackDbLog(customerId, afeNotificationResponse);

            return(Ok(message));
        }