using JMETxnPushScheduler.Common; using Newtonsoft.Json; using Swift.API.Common.Enum; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; namespace JMETxnPushScheduler.API { public static class NotifierV2 { // private static readonly ILog Log = LogManager.GetLogger(typeof(NotifierV2)); public static JsonResponse SendNotification(SendNotificationRequestMobile request, NOTIFICATION_TYPE nOTIFICATION_TYPE = NOTIFICATION_TYPE.PUSH_NOTIFICATION) { using (var client = RestApiClient.CallJMEThirdParty()) { JsonResponse jsonResponse = new JsonResponse(); var obj = JsonConvert.SerializeObject(request); var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json"); try { var URL = "api/v1/TP/NotificationAPI"; HttpResponseMessage resp = client.PostAsync(URL, jbdContent).Result; string resultData = resp.Content.ReadAsStringAsync().Result; if (resp.IsSuccessStatusCode) { jsonResponse = JsonConvert.DeserializeObject(resultData); var a = (jsonResponse.Data != null ? JsonConvert.DeserializeObject(jsonResponse.Data.ToString()) : null); jsonResponse.Data = a; return jsonResponse; } else { var errorJson = JsonConvert.DeserializeObject(resultData); var jsonResponseData = JsonConvert.DeserializeObject(errorJson.Message); var data = JsonConvert.DeserializeObject>(jsonResponseData.Data.ToString()); jsonResponse.Id = jsonResponseData.Id; jsonResponse.ResponseCode = jsonResponseData.ResponseCode; jsonResponse.Msg = jsonResponseData.Msg; jsonResponse.Data = data; jsonResponse.Extra = jsonResponseData.Extra; jsonResponse.Extra1 = jsonResponseData.Extra1; return jsonResponse; } } catch (Exception ex) { return new JsonResponse() { ResponseCode = "1", Msg = (ex.InnerException == null ? ex.Message : ex.InnerException.Message) }; } } } } }