Пример #1
0
        public virtual async Task <IActionResult> ProcessRegistration(bool success, string value)
        {
            if (success)
            {
                var toUpdate = await _pushNotificationsService.GetPushReceiverByCustomerId(_workContext.CurrentCustomer.Id);

                if (toUpdate == null)
                {
                    await _pushNotificationsService.InsertPushReceiver(new PushRegistration
                    {
                        CustomerId   = _workContext.CurrentCustomer.Id,
                        Token        = value,
                        RegisteredOn = DateTime.UtcNow,
                        Allowed      = true
                    });
                }
                else
                {
                    toUpdate.Token        = value;
                    toUpdate.RegisteredOn = DateTime.UtcNow;
                    toUpdate.Allowed      = true;
                    await _pushNotificationsService.UpdatePushReceiver(toUpdate);
                }
            }
            else
            {
                if (value == "Permission denied")
                {
                    var toUpdate = await _pushNotificationsService.GetPushReceiverByCustomerId(_workContext.CurrentCustomer.Id);

                    if (toUpdate == null)
                    {
                        await _pushNotificationsService.InsertPushReceiver(new PushRegistration
                        {
                            CustomerId   = _workContext.CurrentCustomer.Id,
                            Token        = "[DENIED]",
                            RegisteredOn = DateTime.UtcNow,
                            Allowed      = false
                        });
                    }
                    else
                    {
                        toUpdate.Token        = "[DENIED]";
                        toUpdate.RegisteredOn = DateTime.UtcNow;
                        toUpdate.Allowed      = false;
                        await _pushNotificationsService.UpdatePushReceiver(toUpdate);
                    }
                }
            }

            return(new NullJsonResult());
        }
        public void CanGetPushReceiverByCustomerId()
        {
            ClearPushRegistrations();

            var receiver1 = new PushRegistration
            {
                CustomerId = "CanGetPushReceiverByCustomerId1",
                Token      = "CanGetPushReceiverByCustomerIdToken1"
            };

            var receiver2 = new PushRegistration
            {
                CustomerId = "CanGetPushReceiverByCustomerId2",
                Token      = "CanGetPushReceiverByCustomerIdToken2"
            };

            _pushNotificationsService.InsertPushReceiver(receiver1);
            _pushNotificationsService.InsertPushReceiver(receiver2);

            var found = _pushNotificationsService.GetPushReceiverByCustomerId("CanGetPushReceiverByCustomerId1");

            Assert.AreEqual("CanGetPushReceiverByCustomerIdToken1", found.Token);
        }