public ActionResult Index()
 {
     string msh = "";
     string hsenidUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,Url.Content("~"));
   
     RequestMessage msg = new RequestMessage
                              {
                                  applicationID = "",
                                  encoding = RequestEncoding.Text,
                                  message = "4s",
                                  version = "0.23"
                              };
     //SendTest(msg);
     var go = _smscRepository.GetAllNotification();
     return Json(go, JsonRequestBehavior.AllowGet);
 }
        public void ProcessRequest(PgNotification notification, out RequestMessage sms)
        {
            string version = "1.0";
            string password = "******";
            string sourcesAddress = "hewani";
            string AppID = "APP_000007";
            string message = "";
            sms = new RequestMessage();
            if (notification is SmscNotification)
            {
                SmscNotification smsc = notification as SmscNotification;
               message= "Invoice Notification: Thank you for trans ref " + smsc.TransactionId + ". Please pay amount " +
                smsc.Amount.ToString("N2") + " to till No. " + smsc.TillNumber +
                ". " + smsc.Payee;
                var addr = new List<string>();
                addr.Add("tel:" + smsc.OutletPhoneNumber);
                sms = new RequestMessage
                {
                    applicationID = AppID,
                    encoding = RequestEncoding.Text,
                    message = message,
                    address = addr,
                    version = version,
                    binaryHeader = "Content-Type:application/json",
                    chargingAmount = smsc.Amount,
                    password = password,
                    sourceAddress = sourcesAddress,
                    statusRequest = StatusRequest.DeliveryRequestNotRequired,
                };
            }
            else if (notification is SmscPaymentConfirmation)
            {
                SmscPaymentConfirmation smscp = notification as SmscPaymentConfirmation;
                var addr = new List<string>();
                addr.Add("tel:" + smscp.OutletPhoneNumber);
                message = "Payment Confirmation: Thank for your trans ref:  " + smscp.TransactionId +
                          ". Payment amount " + smscp.Amount.ToString("N2") + " to till No.  " + smscp.TillNumber +
                          " Received with thanks. " + smscp.Payee;
                sms = new RequestMessage
                {
                    applicationID = AppID,
                    encoding = RequestEncoding.Text,
                    message = message,
                    address = addr,
                    version = version,
                    binaryHeader = "Content-Type:application/json",
                    chargingAmount = smscp.Amount,
                    password = password,
                    sourceAddress =sourcesAddress,
                    statusRequest = StatusRequest.DeliveryRequestNotRequired,
                };

            }
            else if (notification is Easy247Payment)
            {
                Easy247Payment payment = notification as Easy247Payment;
                var addr = new List<string>();
                addr.Add("tel:" + payment.OutletPhoneNumber);
                message = "Payment Confirmation: Thank for your trans ref:  " + payment.TransactionId +
                          ". Payment amount " + payment.Amount.ToString("N2") + " to Biller No.  " + payment.BillerNumber +
                          " Received with thanks. " + payment.Payee;
                sms = new RequestMessage
                {
                    applicationID = AppID,
                    encoding = RequestEncoding.Text,
                    message = message,
                    address = addr,
                    version = version,
                    binaryHeader = "Content-Type:application/json",
                    chargingAmount = payment.Amount,
                    password = password,
                    sourceAddress = sourcesAddress,
                    statusRequest = StatusRequest.DeliveryRequestNotRequired,
                };
            }
            else if (notification is Eazy247Notification)
            {
                Eazy247Notification easy = notification as Eazy247Notification;
                message = "Invoice Notification: Thank you for trans ref " + easy.TransactionId + ". Please pay amount " +
                 easy.Amount.ToString("N2") + " to Biller No. " + easy.BillerNumber +
                 ". " + easy.Payee;
                var addr = new List<string>();
                addr.Add("tel:" + easy.OutletPhoneNumber);
                sms = new RequestMessage
                {
                    applicationID = AppID,
                    encoding = RequestEncoding.Text,
                    message = message,
                    address = addr,
                    version = version,
                    binaryHeader = "Content-Type:application/json",
                    chargingAmount = easy.Amount,
                    password = password,
                    sourceAddress = sourcesAddress,
                    statusRequest = StatusRequest.DeliveryRequestNotRequired,
                };
            }
           
        }
 private void SaveNSend(PgNotification notification, RequestMessage msg)
 {
    
     SendToHSenid(msg, notification.ReferenceNumber.ToString());
     _smscRepository.Save(notification);
 }
        private void SendToHSenid(RequestMessage msg,string refenceId)
        {
            string mssg = JsonConvert.SerializeObject(msg);
            WebClient wc = new WebClient();
            wc.Encoding = Encoding.UTF8;
            string hsenidUrl = "";// Request.Url.AbsoluteUri.Substring(0, (Request.Url.AbsoluteUri.Length - 1));
            hsenidUrl = SdpHost.GetSdpsmsUri();
            Uri uri = new Uri(hsenidUrl , UriKind.Absolute);
            wc.UploadStringAsync(uri, "POST", mssg);
            wc.UploadStringCompleted += (sender, e) =>
            {
                try
                {
                    if (e.Error != null)
                    {
                        string error = e.Error.Message;
                        return;
                    }

                    string jsonResult = e.Result;
                    RequestResponse response = _notificationDeserialize.SerializeResponse(e.Result);
                  
                    if(response!= null)
                    {
                        response.ReferenceId = refenceId;
                        _responseRepository.Save(response);
                        //SaveResponse(response);
                    }
                }
                catch (Exception ex)
                {

                }
            };

            //new UploadStringCompletedEventHandler(wc_UploadStringCompleted);


        }
 public Thread StartTheSaveAndSendThread(PgNotification smsc, RequestMessage msg)
 {
     var t = new Thread(() => SaveNSend(smsc, msg));
     t.Start();
     return t;
 }