Exemplo n.º 1
0
 public ExternalSms(Sms sms)
 {
     SmsReference = sms.SmsReference;
     From = sms.From.Number;
     To = sms.To.Number;
     Body = sms.Body;
     DateSent = DateTime.Now;//the server will stamp the email outbound
 }
Exemplo n.º 2
0
        public HttpResponseMessage SendSms(Sms sms)
        {
            var result = false;

            //use external service to actually send SMS
            var sendResult = SendExternalSms(sms);

            //create a record in comms if successful
            if(sendResult)
                result  = _smsService.CreateSms(Mapper.Map<Core.Objects.Sms>(sms),false);

            return result
                ? new HttpResponseMessage { StatusCode = HttpStatusCode.Created }
                : new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError };
        }
Exemplo n.º 3
0
        private bool SendExternalSms(Sms sms)
        {
            var jsonSms = JsonConvert.SerializeObject(new ExternalSms(sms));

            var client = new RestClient
            {
                BaseUrl = new Uri("https://letme-transactionalsms.azurewebsites.net/api"),
                Authenticator = new HttpBasicAuthenticator(_apiAuthenticationSettings.AppId,
                    _apiAuthenticationSettings.ApiKey)
            };

            var request = new RestRequest("/sms", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Accept", "application/json");
            request.Parameters.Clear();
            request.AddParameter("application/json", jsonSms, ParameterType.RequestBody);

            var response = client.Execute(request);

            return response.StatusCode != HttpStatusCode.InternalServerError;
        }
Exemplo n.º 4
0
        public HttpResponseMessage UpdateSms(string smsReference, Sms sms)
        {
            var result = _smsService.UpdateSms(smsReference,Mapper.Map<Core.Objects.Sms>(sms));

            return result
                ? new HttpResponseMessage { StatusCode = HttpStatusCode.OK }
                : new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError };
        }