Esempio n. 1
0
        public async Task <PushTokenInsertionResult> CreateAsync(PushNotificationRegistration data)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                // This is a specific case and we do not want to return error,
                // rather we want to update all token information in DB
                // This is related to some providers reusing their tokens
                var entity = await context.PushNotificationRegistrations.FirstOrDefaultAsync(x =>
                                                                                             x.PushRegistrationToken == data.PushRegistrationToken);

                if (entity != null)
                {
                    if (entity.CustomerId != data.CustomerId)
                    {
                        entity.CustomerId       = data.CustomerId;
                        entity.RegistrationDate = data.RegistrationDate;
                        context.PushNotificationRegistrations.Update(entity);
                    }
                    else
                    {
                        return(PushTokenInsertionResult.Ok);
                    }
                }
                else
                {
                    await context.PushNotificationRegistrations.AddAsync(data);
                }

                await context.SaveChangesAsync();

                return(PushTokenInsertionResult.Ok);
            }
        }
Esempio n. 2
0
        public object Delete(PushNotificationRegistration request)
        {
            var account = _accountDao.FindById(new Guid(this.GetSession().UserAuthId));

            _deviceDao.Remove(account.Id, request.DeviceToken);

            return(new HttpResult(HttpStatusCode.OK));
        }
        public async Task <Domain.Enums.PushTokenInsertionResult> RegisterForPushNotificationsAsync(
            PushNotificationRegistration data)
        {
            var validator        = new RegisterForPushNotificationsValidator();
            var validationResult = validator.Validate(data);

            if (!validationResult.IsValid)
            {
                throw new ArgumentException(validationResult.ToString());
            }

            return(await _pushNotificationRegistrationRepository.CreateAsync(data));
        }