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 }
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 }; }
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; }
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 }; }