public async Task <ExecutionResponse <InfobipSendSmsResponse> > SendMessage(InfobipSmsModel model) { var response = new ExecutionResponse <InfobipSendSmsResponse>(); try { string url = infobipConfig.ApiUrl + "/sms/1/text"; string serializedContent = JsonConvert.SerializeObject(model); HttpContent content = new StringContent(serializedContent, Encoding.UTF8, "application/json"); BaseService.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("App", infobipConfig.ApiToken); using (HttpResponseMessage sendResponse = await BaseService.Client.PostAsync(url, content)) { if (sendResponse.StatusCode != HttpStatusCode.OK) { var responseContent = JsonConvert.DeserializeObject(await sendResponse.Content.ReadAsStringAsync()); MessagesHelper.SetValidationMessages(response, "Error", responseContent.ToString(), lang: "en"); return(response); } var res = JsonConvert.DeserializeObject <InfobipSendSmsResponse>(await sendResponse.Content.ReadAsStringAsync()); response.Result = res; response.State = ResponseState.Success; } } catch (Exception ex) { MessagesHelper.SetException(response, ex); } return(response); }
public async Task <ExecutionResponse <BranchCreateLinkResponse> > CreateDeepLink(BranchIoDeepLinkParms deepLinkParms) { ExecutionResponse <BranchCreateLinkResponse> response = new ExecutionResponse <BranchCreateLinkResponse>(); try { string url = branchIoConfig.ApiUrl + "/v1/url"; deepLinkParms.branch_key = branchIoConfig.ApiKey; string serializedContent = JsonConvert.SerializeObject(deepLinkParms); HttpContent content = new StringContent(serializedContent, Encoding.UTF8, "application/json"); using (HttpResponseMessage sendResponse = await BaseService.Client.PostAsync(url, content)) { if (sendResponse.StatusCode != HttpStatusCode.OK) { var responseContent = JsonConvert.DeserializeObject(await sendResponse.Content.ReadAsStringAsync()); MessagesHelper.SetValidationMessages(response, "Error", responseContent.ToString(), lang: "en"); return(response); } var res = JsonConvert.DeserializeObject <BranchCreateLinkResponse>(await sendResponse.Content.ReadAsStringAsync()); response.Result = res; response.State = ResponseState.Success; } } catch (Exception ex) { MessagesHelper.SetException(response, ex); } return(response); }
public static async Task <ExecutionResponse <bool> > SendEmail(SendEmailModel model) { ExecutionResponse <bool> response = new ExecutionResponse <bool>(); try { var from = new EmailAddress(model.SenderEmail, ""); var to = new EmailAddress(model.DeptEmail, ""); var plainTextContent = model.Message; var htmlContent = model.htmlContent; var subject = model.Subject; var email = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); var sendEmailAsyncRes = await sendGridClient.SendEmailAsync(email); if (sendEmailAsyncRes.StatusCode != HttpStatusCode.Accepted) { MessagesHelper.SetValidationMessages(response, "Email_Error", sendEmailAsyncRes.Body.ToString(), lang: "en"); return(response); } response.State = ResponseState.Success; response.Result = true; } catch (Exception ex) { MessagesHelper.SetException(response, ex); } return(response); }
public async Task <ExecutionResponse <OneSignalAddDeviceResponse> > AddDevice(OneSignalDeviceModel device) { ExecutionResponse <OneSignalAddDeviceResponse> response = new ExecutionResponse <OneSignalAddDeviceResponse>(); try { var json_data = JsonConvert.SerializeObject(device); string url = oneSignalConfig.ApiUrl; string serializedContent = JsonConvert.SerializeObject(json_data); HttpContent content = new StringContent(serializedContent, Encoding.UTF8, "application/json"); using (HttpResponseMessage sendResponse = await BaseService.Client.PostAsync(url, content)) { if (sendResponse.StatusCode != HttpStatusCode.OK) { var responseContent = JsonConvert.DeserializeObject(await sendResponse.Content.ReadAsStringAsync()); MessagesHelper.SetValidationMessages(response, "Error", responseContent.ToString(), lang: "en"); return(response); } var res = JsonConvert.DeserializeObject <OneSignalAddDeviceResponse>(await sendResponse.Content.ReadAsStringAsync()); response.Result = res; response.State = ResponseState.Success; } } catch (Exception ex) { MessagesHelper.SetException(response, ex); } return(response); }