コード例 #1
0
        public HttpResponseMessage sendverificationnotification(int issueId)
        {
            var list = dbe.nearby_user_table.Where(x => x.issue_id == issueId).ToList();

            if (list != null)
            {
                foreach (var item in list)
                {
                    List <string> tokenList = new List <string>();
                    try
                    {
                        var token = dbe.FCM_TOKEN.Where(x => x.UserID == item.user_id).FirstOrDefault();
                        if (token != null)
                        {
                            tokenList.Add(token.Token);
                            pushnotification notification = new pushnotification()
                            {
                                title = "Issue Verification", body = "Please verify this issue in your area", issueid = issueId.ToString(), userid = item.user_id.ToString()
                            };
                            var json = JsonConvert.SerializeObject(notification);
                            SendNotification(tokenList, json);
                        }
                    }
                    catch (Exception) { }
                }
                return(Request.CreateResponse(HttpStatusCode.Accepted, "Verification Notification sent"));
            }

            return(Request.CreateResponse(HttpStatusCode.NotFound, "No nearby users found"));
        }
コード例 #2
0
        public HttpResponseMessage SendNotificationToAUser(string title, string body, int userId)
        {
            pushnotification notification = new pushnotification()
            {
                title = title, body = body
            };
            string json  = JsonConvert.SerializeObject(notification);
            var    token = dbe.FCM_TOKEN.Where(x => x.UserID == userId).FirstOrDefault();

            if (token != null)
            {
                List <string> tokenList = new List <string>();
                tokenList.Add(token.Token);
                SendNotification(tokenList, json);
                return(Request.CreateResponse(HttpStatusCode.Accepted, ""));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, ""));
        }
コード例 #3
0
        public IHttpActionResult SendPushNotification([FromBody] notification noti)
        {
            var DeviceTokenList = GetAllTokens();

            pushnotification notification = new pushnotification();

            notification.title = noti.notification_title;
            notification.body  = noti.notification_text;
            NotificationTable table = new NotificationTable();

            table.notification_image = noti.notification_image;
            table.notification_text  = noti.notification_text;
            table.notification_title = noti.notification_title;
            table.notification_date  = DateTime.Now;
            dbe.NotificationTable.Add(table);
            dbe.SaveChanges();
            var Json = JsonConvert.SerializeObject(notification);

            SendNotification(DeviceTokenList, Json);
            return(Ok());
        }