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)); }
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] NotificationHubs.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)); }
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)); }