Ejemplo n.º 1
0
        public ObjectResult Subscribe(string name, [FromBody] PushSubscriptionJson subscription)
        {
            User user = DbContext.Users
                        .Include(u => u.Subscriptions)
                        .FirstOrDefault(u => u.Login == name);

            if (user != null)
            {
                Subscription sub = new Subscription()
                {
                    PushEndpoint = subscription.endpoint,
                    PushAuth     = subscription.keys.auth,
                    PushP256dh   = subscription.keys.p256dh,
                    UserLogin    = user.Login,
                    RelUser      = user
                };
                user.Subscriptions.Add(sub);
                DbContext.SaveChanges();
                subscription.id = sub.Id;
                return(StatusCode(200, subscription));
            }
            else
            {
                return(StatusCode(404, new { error = "No such user!" }));
            }
        }
Ejemplo n.º 2
0
        public IActionResult Register([FromBody] PushSubscriptionJson subscription)
        {
            _pushService.Register(new PushSubscription(subscription.Endpoint, subscription.Keys.P256DH, subscription.Keys.Auth));

            return(Ok(JsonConvert.SerializeObject("ok")));
        }