private DataTable getAllDeviceIDForNotification() { BusinessLayer.Common.SMSMemberMaster objMember = new BusinessLayer.Common.SMSMemberMaster(); DataView DV = new DataView(objMember.GetAllDeviceIdForNotification()); return(DV.ToTable()); }
protected void btnSentNotification_Click(object sender, EventArgs e) { BusinessLayer.Common.SMSMemberMaster objMember = new BusinessLayer.Common.SMSMemberMaster(); DataTable dtMembers = objMember.GetAllDeviceIdForNotification(); foreach (DataRow member in dtMembers.Rows) { if (member["DeviceId"] != null) { string ImageUrl = "http://api.wbpoultryfederation.org/Images/Poultry_LargeIcon.jpg"; var request = WebRequest.Create("https://onesignal.com/api/v1/notifications") as HttpWebRequest; request.KeepAlive = true; request.Method = "POST"; request.ContentType = "application/json; charset=utf-8"; request.Headers.Add("authorization", "OGYtYjE2NS00NDE4LThODdjNGUxlMTUtZmQ2ZjJkODg0ZGJl"); byte[] byteArray = Encoding.UTF8.GetBytes("{" + "\"app_id\": \"a4143c17-1b1b-42f3-bb2d-9a25295de246\"," + "\"large_icon\" : \" " + ImageUrl + " \", " + "\"data\": {\"NotificationType\": \"Loading\"}," + "\"contents\": {\"en\": \"WBPF - Bird rate published for today.Please Login to APP and Check!!\"}," + "\"include_player_ids\": [\"" + member["DeviceId"].ToString() + "\"]}"); string responseContent = null; try { using (var writer = request.GetRequestStream()) { writer.Write(byteArray, 0, byteArray.Length); } using (var response = request.GetResponse() as HttpWebResponse) { using (var reader = new StreamReader(response.GetResponseStream())) { responseContent = reader.ReadToEnd(); } } ShowMsg("Notification Send Successfully"); } catch (WebException ex) { System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd()); } } } }