예제 #1
0
        public async Task SendNotification(NotificationScope scope, object notification)
        {
            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }
            var users = await GetUsers(scope);

            using (var db = _contextFactory.CreateContext())
            {
                foreach (var uid in users)
                {
                    var obj  = JsonConvert.SerializeObject(notification);
                    var data = new NotificationData
                    {
                        Id                = Guid.NewGuid().ToString(),
                        Created           = DateTimeOffset.UtcNow,
                        ApplicationUserId = uid,
                        NotificationType  = _notificationManager.GetHandler(notification.GetType()).NotificationType,
                        Blob              = ZipUtils.Zip(obj),
                        Seen              = false
                    };
                    db.Notifications.Add(data);
                }
                await db.SaveChangesAsync();
            }
            foreach (string user in users)
            {
                _notificationManager.InvalidateNotificationCache(user);
            }
        }
예제 #2
0
        public async Task SendNotification(NotificationScope scope, BaseNotification notification)
        {
            ArgumentNullException.ThrowIfNull(scope);
            ArgumentNullException.ThrowIfNull(notification);
            var users = await GetUsers(scope, notification.Identifier);

            await using (var db = _contextFactory.CreateContext())
            {
                foreach (var uid in users)
                {
                    var obj  = JsonConvert.SerializeObject(notification);
                    var data = new NotificationData
                    {
                        Id                = Guid.NewGuid().ToString(),
                        Created           = DateTimeOffset.UtcNow,
                        ApplicationUserId = uid,
                        NotificationType  = notification.NotificationType,
                        Blob              = ZipUtils.Zip(obj),
                        Seen              = false
                    };
                    await db.Notifications.AddAsync(data);
                }
                await db.SaveChangesAsync();
            }
            foreach (string user in users)
            {
                _notificationManager.InvalidateNotificationCache(user);
            }
        }