public BulkNotificationResponse jsonToDataTableNotify(string json) { DataTable dt = new DataTable(); BulkNotificationResponse m = JsonConvert.DeserializeObject <BulkNotificationResponse>(json); return(m); }
private async Task <BulkNotificationResponse> GetBulkNotification(int notificationId) { string url = $"{NotificationsApiUrl}BulkNotifications/GetById?notificationId={notificationId}"; var BulkNotification = new BulkNotificationResponse(); var accessToken = await HttpContext.GetTokenAsync("access_token"); var response = await HttpRequestFactory.Get(accessToken, url); if (response.StatusCode == HttpStatusCode.OK) { BulkNotification = response.ContentAsType <BulkNotificationResponse>(); } else { ModelState.AddModelError("", HttpResponseHandler.Process(response)); } return(BulkNotification); }
//type ={ image/text /update} //sendtype={1= One by one / 0= bulk} public bool SendImageNotification(String Mobile, int batchid, string type, int sendtype, string applicationID, string SENDER_ID, String Message = "", String ImgUrl = "", String UserId = "", String RequestId = "", bool isCustomer = true) { Boolean res = false; //string[] param = { Mobile }; string strTaaza_Notification_Detail = string.Empty; string Devicedetails = string.Empty; if (isCustomer) { strTaaza_Notification_Detail = "_Customer"; Devicedetails = "Customer"; } try { // WCL("SendImageNotification() 5228 call BatchId:" + batchid + " MobileNo:" + Mobile + " Msg:" + Message + " ImgUrl:" + ImgUrl); if (!String.IsNullOrWhiteSpace(Mobile)) { bool isAll = (Mobile.ToLower().Contains("all") ? true : false); String Str = ""; String mobileNo = ""; if (isAll) { Str = "select * from [dbo].[Devicedetails" + Devicedetails + "]"; } else { string[] parts = Mobile.Split(','); if (parts.Length > 0) { for (int i = 0; i < parts.Length; i++) { mobileNo += "'" + parts[i] + "',"; } } mobileNo = mobileNo.TrimEnd(','); Str = "select isnull(deviceid,'') as deviceid,isnull(fcmregistrationid,'') as fcmregistrationid ,mobilenumber,[doc],dom,Id from [dbo].[Devicedetails" + Devicedetails + "] where mobilenumber in(" + mobileNo + ")"; } DataTable dt = dbCon.GetDataTable(Str); if (dt != null && dt.Rows.Count > 0) { if (ImgUrl != null && ImgUrl != "") { int a = 0; if (sendtype == 0) //Bulk Notification { int c = 0; List <string> lis = new List <string>(); DataTable dttemp = dt.Clone(); for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; if (!String.IsNullOrWhiteSpace(dr["fcmregistrationid"].ToString()) && !String.IsNullOrWhiteSpace(dr["deviceid"].ToString())) { lis.Add(dr["fcmregistrationid"].ToString()); a++; c++; dttemp.ImportRow(dr); } if (c == 10) { String response = SendPushNotification((isCustomer ? "Customer" : "Store"), lis, Message, type, batchid, applicationID, SENDER_ID, ImgUrl, UserId, RequestId); c = 0; BulkNotificationResponse obj = jsonToDataTableNotify(response); List <string> paramlist = new List <string>(); StringBuilder sb = new StringBuilder(); int count = 0; sb.Append("INSERT INTO [dbo].[Taaza_Notification_Detail" + strTaaza_Notification_Detail + "] ([DeviceId],[FCMRegistrationId],[Message],[ResponseId],[Type],[DOC],[Mobile],[Batchmasterid]) VALUES "); for (int k = 0; k < dttemp.Rows.Count; k++) { DataRow dr1 = dttemp.Rows[k]; string ReturnMessageId = "0"; if (obj.results[k].message_id != null) { string[] resulsplit = obj.results[k].message_id.Split(':'); ReturnMessageId = resulsplit[1].ToString(); } sb.Append("("); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["deviceid"].ToString()); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["fcmregistrationid"].ToString()); count++; sb.Append("@" + count + ","); paramlist.Add(Message); count++; sb.Append("@" + count + ","); paramlist.Add(ReturnMessageId); count++; sb.Append("@" + count + ","); paramlist.Add(type); sb.Append("dateadd(minute, 330, getutcdate()),"); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["mobilenumber"].ToString()); count++; sb.Append("@" + count); paramlist.Add(batchid.ToString()); sb.Append("),"); } string qry = sb.ToString().TrimEnd(new char[] { ',' }) + ";"; string[] parm = paramlist.Select(j => j.ToString()).ToArray(); int i2 = dbCon.ExecuteQueryWithParams(qry, parm); lis = new List <string>(); dttemp.Clear(); } else if (a == dt.Rows.Count) { String response = SendPushNotification((isCustomer ? "Customer" : "Store"), lis, Message, type, batchid, applicationID, SENDER_ID, ImgUrl, UserId, RequestId); BulkNotificationResponse obj = jsonToDataTableNotify(response); List <string> paramlist = new List <string>(); StringBuilder sb = new StringBuilder(); int count = 0; sb.Append("INSERT INTO [dbo].[Taaza_Notification_Detail" + strTaaza_Notification_Detail + "] ([DeviceId],[FCMRegistrationId],[Message],[ResponseId],[Type],[DOC],[Mobile],[Batchmasterid]) VALUES "); for (int k = 0; k < dttemp.Rows.Count; k++) { DataRow dr1 = dttemp.Rows[k]; string ReturnMessageId = "0"; if (obj.results[k].message_id != null) { string[] resulsplit = obj.results[k].message_id.Split(':'); ReturnMessageId = resulsplit[1].ToString(); } sb.Append("("); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["deviceid"].ToString()); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["fcmregistrationid"].ToString()); count++; sb.Append("@" + count + ","); paramlist.Add(Message); count++; sb.Append("@" + count + ","); paramlist.Add(ReturnMessageId); count++; sb.Append("@" + count + ","); paramlist.Add(type); sb.Append("dateadd(minute, 330, getutcdate()),"); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["mobilenumber"].ToString()); count++; sb.Append("@" + count); paramlist.Add(batchid.ToString()); sb.Append("),"); } string qry = sb.ToString().TrimEnd(new char[] { ',' }) + ";"; string[] parm = paramlist.Select(j => j.ToString()).ToArray(); int i2 = dbCon.ExecuteQueryWithParams(qry, parm); c = 0; lis = new List <string>(); dttemp.Clear(); } } } else // Individual Notification { foreach (DataRow dr in dt.Rows) { if (!String.IsNullOrWhiteSpace(dr["fcmregistrationid"].ToString()) && !String.IsNullOrWhiteSpace(dr["deviceid"].ToString())) { NotifyDevice(dr["fcmregistrationid"].ToString(), Message, type + "", dr["deviceid"].ToString(), batchid, applicationID, SENDER_ID, dr["mobilenumber"].ToString(), ImgUrl, UserId, RequestId, isCustomer: isCustomer); } else { WCL("SendImageNotification() 5367: No Device found for this mobile no:" + Mobile); // Insert Log } } } } else { WCL("SendImageNotification() 5374 TotalRecordFound:" + dt.Rows.Count); int a = 0; if (sendtype == 0) //Bulk Notification { int c = 0; List <string> lis = new List <string>(); DataTable dttemp = dt.Clone(); for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; if (!String.IsNullOrWhiteSpace(dr["fcmregistrationid"].ToString()) && !String.IsNullOrWhiteSpace(dr["deviceid"].ToString())) { lis.Add(dr["fcmregistrationid"].ToString()); a++; c++; dttemp.ImportRow(dr); } if (c == 10) { String response = SendPushNotification((isCustomer ? "Customer" : "Store"), lis, Message, type, batchid, applicationID, SENDER_ID, ImgUrl, UserId, RequestId); c = 0; BulkNotificationResponse obj = jsonToDataTableNotify(response); List <string> paramlist = new List <string>(); StringBuilder sb = new StringBuilder(); int count = 0; sb.Append("INSERT INTO [dbo].[Taaza_Notification_Detail" + strTaaza_Notification_Detail + "] ([DeviceId],[FCMRegistrationId],[Message],[ResponseId],[Type],[DOC],[Mobile],[Batchmasterid]) VALUES "); for (int k = 0; k < dttemp.Rows.Count; k++) { DataRow dr1 = dttemp.Rows[k]; string ReturnMessageId = "0"; if (obj.results[k].message_id != null) { string[] resulsplit = obj.results[k].message_id.Split(':'); ReturnMessageId = resulsplit[1].ToString(); } sb.Append("("); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["deviceid"].ToString()); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["fcmregistrationid"].ToString()); count++; sb.Append("@" + count + ","); paramlist.Add(Message); count++; sb.Append("@" + count + ","); paramlist.Add(ReturnMessageId); count++; sb.Append("@" + count + ","); paramlist.Add(type); sb.Append("dateadd(minute, 330, getutcdate()),"); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["mobilenumber"].ToString()); count++; sb.Append("@" + count); paramlist.Add(batchid.ToString()); sb.Append("),"); } string qry = sb.ToString().TrimEnd(new char[] { ',' }) + ";"; string[] parm = paramlist.Select(j => j.ToString()).ToArray(); int i2 = dbCon.ExecuteQueryWithParams(qry, parm); lis = new List <string>(); dttemp.Clear(); } else if (a == dt.Rows.Count) { String response = SendPushNotification((isCustomer ? "Customer" : "Store"), lis, Message, type, batchid, applicationID, SENDER_ID, ImgUrl, UserId, RequestId); BulkNotificationResponse obj = jsonToDataTableNotify(response); List <string> paramlist = new List <string>(); StringBuilder sb = new StringBuilder(); int count = 0; sb.Append("INSERT INTO [dbo].[Taaza_Notification_Detail" + strTaaza_Notification_Detail + "] ([DeviceId],[FCMRegistrationId],[Message],[ResponseId],[Type],[DOC],[Mobile],[Batchmasterid]) VALUES "); for (int k = 0; k < dttemp.Rows.Count; k++) { DataRow dr1 = dttemp.Rows[k]; string ReturnMessageId = "0"; if (obj.results[k].message_id != null) { string[] resulsplit = obj.results[k].message_id.Split(':'); ReturnMessageId = resulsplit[1].ToString(); } sb.Append("("); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["deviceid"].ToString()); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["fcmregistrationid"].ToString()); count++; sb.Append("@" + count + ","); paramlist.Add(Message); count++; sb.Append("@" + count + ","); paramlist.Add(ReturnMessageId); count++; sb.Append("@" + count + ","); paramlist.Add(type); sb.Append("dateadd(minute, 330, getutcdate()),"); count++; sb.Append("@" + count + ","); paramlist.Add(dr1["mobilenumber"].ToString()); count++; sb.Append("@" + count); paramlist.Add(batchid.ToString()); sb.Append("),"); } string qry = sb.ToString().TrimEnd(new char[] { ',' }) + ";"; string[] parm = paramlist.Select(j => j.ToString()).ToArray(); int i2 = dbCon.ExecuteQueryWithParams(qry, parm); c = 0; lis = new List <string>(); dttemp.Clear(); } } } else // Individual Notification { foreach (DataRow dr in dt.Rows) { //testing jd if (!String.IsNullOrWhiteSpace(dr["fcmregistrationid"].ToString()) && !String.IsNullOrWhiteSpace(dr["deviceid"].ToString())) { NotifyDevice(dr["fcmregistrationid"].ToString(), Message, type, dr["deviceid"].ToString(), batchid, applicationID, SENDER_ID, dr["mobilenumber"].ToString(), UserId: UserId, RequestId: RequestId, isCustomer: isCustomer); } else { WCL("SendImageNotification() 5381: No Device found for this mobile no:" + Mobile); // Insert Log } } } } // } res = true; } else { WCL("SendImageNotification() 5392: No UserFound Query:" + Str); } } else { WCL("SendImageNotification() 5397: Mobileno or imgurl not proper Mobile:" + Mobile + " Imgurl:" + ImgUrl); } return(res); } catch (Exception ex) { WCL("SendImageNotification() 5401 call MobileNo:" + Mobile + " Msg:" + Message + " ImgUrl:" + ImgUrl + " \nException:" + ex.Message + " ::::::::: " + ex.StackTrace); // dbCon.InsertLogs(LOGS.LogLevel.Error, "SendImageNotification Error", "SendImageNotification() 3897 call Msg:" + Message + " ImgUrl:" + ImgUrl + " \nException:" + ex.Message + " ::::::::: " + ex.StackTrace, "-10"); return(false); } }