Пример #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Item).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemExists(Item.Objectid))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Пример #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Items.Add(Item);

            await _context.SaveChangesAsync();

            //use your own private and public key:
            //generator here: https://web-push-codelab.glitch.me/
            var vapidDetails = new VapidDetails(@"<youremail>",
                                                "<publickey>",
                                                "<privatekey>");

            var pushSubscriptions = await _context.PushSubscriptions.ToListAsync();

            var webPushClient = new WebPushClient();

            var tasks = new List <Task>();

            foreach (var pushSubscription in pushSubscriptions)
            {
                var webPushSubscription = new WebPush.PushSubscription(pushSubscription.EndPoint, pushSubscription.P256dh, pushSubscription.Auth);

                tasks.Add(webPushClient.SendNotificationAsync(webPushSubscription, "test", vapidDetails));
            }

            await Task.WhenAll(tasks);

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Item = await _context.Items.FindAsync(id);

            if (Item != null)
            {
                _context.Items.Remove(Item);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }