Пример #1
0
        public async Task <IActionResult> Create(ItemModel item)
        {
            await repository.InsertOneAsync(item);

            var subscribers = await pushRepository.GetAllAsync();

            string           vapidPublicKey  = _config.GetSection("VapidKeys")["PublicKey"];
            string           vapidPrivateKey = _config.GetSection("VapidKeys")["PrivateKey"];
            PushPayloadModel payload         = new PushPayloadModel {
                message = item.Description, title = "Nuovo articolo pubblicato"
            };

            foreach (var device in subscribers)
            {
                var pushSubscription = new PushSubscription(device.PushEndpoint, device.PushP256DH, device.PushAuth);
                var vapidDetails     = new VapidDetails("mailto:[email protected]", vapidPublicKey, vapidPrivateKey);
                var webPushClient    = new WebPushClient();
                webPushClient.SendNotification(pushSubscription, JsonConvert.SerializeObject(payload), vapidDetails);
            }
            return(RedirectToAction("Index"));
        }
Пример #2
0
 // GET: Devices
 public async Task <IActionResult> Index()
 {
     return(View(await repository.GetAllAsync()));
 }