Example #1
0
        public int Save(DocSMS entity)
        {
            tblSms tsms = _ctx.tblSms.FirstOrDefault(n => n.Id == entity.Id);
            if (tsms == null)
            {
                tsms = new tblSms();
                tsms.Id = entity.Id;
                tsms.DateCreated = DateTime.Now;
                _ctx.tblSms.Add(tsms);
            }
            tsms.DateLastUpdated = DateTime.Now;
            tsms.ClientRequestResponseType = (int) ClientRequestResponseType.SMS;
            tsms.DistributorCostCenterId = entity.DistributorCostCenterId;
            tsms.DocumentId = entity.DocumentId;
            tsms.DocumentType = entity.DocumentType;
            tsms.Recipients = JsonConvert.SerializeObject(entity.Recipitents);
            tsms.SMSBody = entity.SmsBody;
            tsms.SmsStatus = SmsStatuses.Pending.ToString();

            return _ctx.SaveChanges();
        }
        SDPSMSResponse HSenidSend(SDPSMSRequest sdpSms, DocSMS clientSms)
        {
            SDPSMSResponse response;
            string jsonRequest = JsonConvert.SerializeObject(sdpSms);
            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);

            _auditLogRepository.AddLog(clientSms.DistributorCostCenterId, "SMS Request", "To HSenid", string.Format("Json SMS Request: {0}", jsonRequest));
            string jsonResponse = wc.UploadString(uri, "POST", jsonRequest);
            _messageValidation.CanDeserializeMessage(jsonResponse, out response);
            _auditLogRepository.AddLog(clientSms.DistributorCostCenterId,"SMS Response","From HSenid", string.Format("Json SMS Response: {0}", jsonResponse));
            
            return response;
        }
        public HttpResponseMessage SendSMS(DocSMS clientSms)
        {
            DocSMSResponse pgresponse = new DocSMSResponse();
            pgresponse.SmsStatus = SmsStatuses.Pending;
            try
            {
                ServiceProvider sp = _resolveMessageService.GetServiceProvider(clientSms.DistributorCostCenterId);
                if (sp == null)
                {
                    pgresponse.SdpResponseStatus = "This service provider is not registered.";
                }
                else
                {
                    ServerRequestBase sdpSms;
                    _resolveMessageService.ProcessClientRequest(clientSms, sp, out sdpSms);
                    SDPSMSResponse sdpResponse = HSenidSend(sdpSms as SDPSMSRequest, clientSms);

                    _docSMSRepository.Save(clientSms);

                    pgresponse.SmsStatus = SmsStatuses.Sent;
                    pgresponse.ClientRequestResponseType = ClientRequestResponseType.SMS;
                    pgresponse.DateCreated = DateTime.Now;
                    pgresponse.DistributorCostCenterId = clientSms.DistributorCostCenterId;
                    pgresponse.TransactionRefId = sdpResponse.requestId;
                    pgresponse.Id = clientSms.Id;
                    pgresponse.SdpVersion = sdpResponse.version;
                    pgresponse.SdpResponseStatus = sdpResponse.statusDetail;
                    pgresponse.SdpResponseCode = sdpResponse.statusCode;
                    pgresponse.SdpDestinationResponses = sdpResponse.destinationResponses;
                    pgresponse.SdpRequestId = sdpResponse.requestId;
                    pgresponse.SmsStatus = SmsStatuses.Sent;

                    _docSMSRepository.SaveResponse(pgresponse);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }


            return Request.CreateResponse(HttpStatusCode.OK, pgresponse);
        }
 public async Task<DocSMSResponse> SendDocSms(DocSMS docSms)
 {
     DocSMSResponse _response = new DocSMSResponse {SmsStatus = SmsStatuses.Pending};
     HttpClient httpClient = setupHttpClient();
     httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
     string url = "api/gateway/sms/send";
     try
     {
         var response = await httpClient.PostAsJsonAsync(url, docSms);
         _response = await response.Content.ReadAsAsync<DocSMSResponse>();
     }
     catch (Exception ex)
     {
         string error = "Failed to forward sms for sending.\n" +
                        (ex.InnerException == null ? "" : ex.InnerException.Message);
         _response.SdpResponseCode = "Error";
         _response.SdpResponseStatus = error;
     }
     return _response;
 }