private bool SendNotification(PushNotificationLogs fcmdevices) { bool status = true; try { WebRequest tRequest = WebRequest.Create(Utilities.fcmURL); tRequest.Method = "post"; tRequest.ContentType = "application/json"; var data = new { to = Utilities.deviceToken, priority = Utilities.priority, notification = new { body = fcmdevices.Topic, title = "Ïnitiative Campaign", notification_id = fcmdevices.InitiativeCampaignId } }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", _config.ApplicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", _config.SenderID)); tRequest.ContentLength = byteArray.Length; using (Stream dataStream = tRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse tResponse = tRequest.GetResponse()) { using (Stream dataStreamResponse = tResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromServer = tReader.ReadToEnd(); JObject sResponse = JObject.Parse(sResponseFromServer); status = Convert.ToInt32(sResponse["success"]) == 1 ? true : false; } } } } } catch (Exception) { status = false; } return(status); }
public void ProcessCampaign(IList <Campaign> campaigns) { //log.Info(String.Format("Start Processing:{0}", campaigns.Count.ToString())); if (campaigns.Count > 0) { campaigns.ToList().ForEach(x => { if (x.Initiative != null) { var runToday = x.Initiative.InitiativeCampaign.Where(dt => dt.StartDateTime.Value.Date.Equals(DateTime.Now.Date)); runToday.ToList().ForEach(y => { //log.Info(String.Format("Start Processing Campaign:{0}", y.Id)); var isExists = _notificationService.GetNotificationByInitiativeCampaignId(Convert.ToInt32(y.Id)); if (isExists != null) { isExists.SendCnt = isExists.SendCnt + 1; isExists.UpdatedBy = 1; isExists.UpdatedOn = DateTime.Now; if (SendNotification(isExists)) { _notificationService.UpdateNotification(isExists); } } else { PushNotificationLogs push = new PushNotificationLogs(); push.CreatedBy = 1; push.CreatedOn = DateTime.Now; push.InitiativeCampaignId = y.Id; push.SendCnt = 1; push.NotificationType = (int)NotificationType.PushNotification; push.Topic = y.Description; if (SendNotification(push)) { _notificationService.CreateNotification(push); } } // log.Info(String.Format("End Processing Campaign:{0}", y.Id)); }); } }); } //log.Info(String.Format("End Processing:{0}", campaigns.Count.ToString())); }
public bool SendEmail(PushNotificationLogs notification) { throw new NotImplementedException(); }
public bool SendNotification(PushNotificationLogs notification) => _notification.SendToSingle(notification);
public bool SendToSingle(PushNotificationLogs fcmdevice) { bool status = SendNotification(fcmdevice); return(status); }
public bool SendSMS(PushNotificationLogs campaign) { throw new System.NotImplementedException(); }
public bool SendNotification(PushNotificationLogs campaign) { return(_notification.SendToSingle(campaign)); }
public int UpdateNotification(PushNotificationLogs notification) { return(_repoNotification.UpdateNotification(notification)); }
public int DeleteNotification(PushNotificationLogs notifications) { return(_repoNotification.DeleteNotification(notifications)); }
public int CreateNotification(PushNotificationLogs notifications) { return(_repoNotification.CreateNotification(notifications)); }