public async Task <IActionResult> SendNotification([FromBody] NotificationHubs.Notification newNotification)
        {
            var content = JsonConvert.SerializeObject(new
            {
                Message = new
                {
                    Token        = "",
                    Notification = new
                    {
                        Body  = "This is an FCM notification message!",
                        Title = "FCM Message",
                    }
                }
            });

            newNotification.Content = content;

            HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification);

            if (pushDeliveryResult.CompletedWithSuccess)
            {
                return(Ok());
            }

            return(BadRequest("An error occurred while sending push notification: " + pushDeliveryResult.FormattedErrorMessages));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(Guid id, [FromForm] Plant plant)
        {
            if (id != plant.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var plantDb = await _context.Plants
                                  .FirstOrDefaultAsync(m => m.Id == id);

                    plantDb.Name            = plant.Name;
                    plantDb.PlantFileUrl    = plant.PlantFileUrl;
                    plantDb.Points          = plant.Points;
                    plantDb.DeviceId        = plant.DeviceId;
                    plantDb.ScientificName  = plant.ScientificName;
                    plantDb.Family          = plant.Family;
                    plantDb.Description     = plant.Description;
                    plantDb.Surrounding     = plant.Surrounding;
                    plantDb.EndangeredLevel = plant.EndangeredLevel;

                    _context.Update(plantDb);
                    await _context.SaveChangesAsync();

                    var deviceId = await _context.PushRegistrations.FirstOrDefaultAsync(f => f.DeviceId == plantDb.DeviceId);

                    if (deviceId != null)
                    {
                        HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(new NotificationHubs.PushNotification
                        {
                            Content = $"One of your plants is updated: {plantDb.Points} points",
                            Tags    = new string[1] {
                                deviceId.Tag
                            },
                            Platform = deviceId.MobilePlatform
                        });
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlantExists(plant.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(plant));
        }
        public async Task <IActionResult> Create(NotificationHubs.Notification newNotification)
        {
            HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification);

            if (pushDeliveryResult.CompletedWithSuccess)
            {
                return(RedirectToAction(nameof(Index)));
            }
            return(BadRequest("An error occurred while sending push notification: " + pushDeliveryResult.FormattedErrorMessages));
        }
        public async Task <IActionResult> SendNotification([FromBody] Notification newNotification)
        {
            HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification);

            if (pushDeliveryResult.CompletedWithSuccess)
            {
                return(Ok());
            }

            return(BadRequest("An error occurred while sending push notification: " + pushDeliveryResult.FormattedErrorMessages));
        }
Beispiel #5
0
        public async Task <IActionResult> SendNotification([FromBody] Common.Notification.Notification newNotification)
        {
            HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification, _hubSignalRContext);

            if (pushDeliveryResult.CompletedWithSuccess)
            {
                return(Ok());
            }

            return(StatusCode((int)HttpStatusCode.NoContent));
        }
Beispiel #6
0
        private async void SendPushMessage(Message msg)
        {
            // send message
            string toast = "{\"aps\":{\"alert\":{\"title\" : \"Received message:\", \"subtitle\" : \"" + msg.MessageFrom + "\",\"body\": \"" + msg.MessageText + "\"}}}";

            foreach (string userHandle in msg.UserIds)
            {
                await notifications.SendNotification(new Notification()
                {
                    Content  = toast,
                    Platform = MobilePlatform.apns,
                    Handle   = userHandle
                });
            }
        }
        private async void SendPushNotification(VoteRequest request)
        {
            // send message
            string toast = "{\"aps\":{\"alert\":{\"title\" : \"Požadavek na hodnocení výuky\" }}}";

            foreach (string userHandle in request.UserToRequestIds)
            {
                await notifications.SendNotification(new Notification()
                {
                    Content  = toast,
                    Platform = MobilePlatform.apns,
                    Handle   = userHandle
                });
            }
        }
        public async Task <IActionResult> SendNotification()
        {
            var notification = new Notification()
            {
                Content = "{\"notification\":{\"title\":\"Notification Hub Test Notification\"," +
                          "\"body\":\"This is a sample notification delivered by Azure Notification Hubs.\"}" +
                          ",\"data\":{\"property1\":\"value1\",\"property2\":42}}"
            };


            HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(notification);

            if (pushDeliveryResult.CompletedWithSuccess)
            {
                return(Ok());
            }

            return(BadRequest("An error occurred while sending push notification: " + pushDeliveryResult.FormattedErrorMessages));
        }
        public async Task <ActionResult <User> > PostUser(User user)
        {
            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            await _context.SaveChangesAsync();

            NotificationHubProxy _notificationHubProxy = new NotificationHubProxy(standardNotificationHubConfiguration);

            NotificationHubs.Notification newNotification = new NotificationHubs.Notification();
            newNotification.Content = "New user created: id = " + user.Id;
            newNotification.Title   = "New user";
            HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification);

            if (pushDeliveryResult.CompletedWithSuccess)
            {
                Console.WriteLine("Push Message Succesful");
            }

            return(CreatedAtAction("GetUser", new { id = user.Id }, user));
        }
 private async void SendNotification(PushNotificationIntegrationEvent newNotification)
 {
     HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification);
 }