protected virtual List <UserNotification> SaveUserNotifications(UserIdentifier[] users, NotificationInfo notificationInfo)
        {
            var userNotifications = new List <UserNotification>();

            var tenantGroups = users.GroupBy(user => user.TenantId);

            foreach (var tenantGroup in tenantGroups)
            {
                using (_unitOfWorkManager.Current.SetTenantId(tenantGroup.Key))
                {
                    var tenantNotificationInfo = new TenantNotificationInfo(_guidGenerator.Create(), tenantGroup.Key, notificationInfo);
                    _notificationStore.InsertTenantNotification(tenantNotificationInfo);
                    _unitOfWorkManager.Current.SaveChanges(); //To get tenantNotification.Id.

                    var tenantNotification = tenantNotificationInfo.ToTenantNotification();

                    foreach (var user in tenantGroup)
                    {
                        var userNotification = new UserNotificationInfo(_guidGenerator.Create())
                        {
                            TenantId             = tenantGroup.Key,
                            UserId               = user.UserId,
                            TenantNotificationId = tenantNotificationInfo.Id
                        };

                        _notificationStore.InsertUserNotification(userNotification);
                        userNotifications.Add(userNotification.ToUserNotification(tenantNotification));
                    }

                    CurrentUnitOfWork.SaveChanges(); //To get Ids of the notifications
                }
            }

            return(userNotifications);
        }
 public virtual void InsertUserNotification(UserNotificationInfo userNotification)
 {
     using (_unitOfWorkManager.Current.SetTenantId(userNotification.TenantId))
     {
         _userNotificationRepository.Insert(userNotification);
         _unitOfWorkManager.Current.SaveChanges();
     }
 }
 public virtual async Task InsertUserNotificationAsync(UserNotificationInfo userNotification)
 {
     using (_unitOfWorkManager.Current.SetTenantId(userNotification.TenantId))
     {
         await _userNotificationRepository.InsertAsync(userNotification);
         await _unitOfWorkManager.Current.SaveChangesAsync();
     }
 }
        public virtual async Task InsertUserNotificationAsync(UserNotificationInfo userNotification)
        {
            using (_unitOfWorkManager.Current.SetTenantId(userNotification.TenantId))
            {
                await _userNotificationRepository.InsertAsync(userNotification);

                await _unitOfWorkManager.Current.SaveChangesAsync();
            }
        }
 public Task InsertUserNotificationAsync(UserNotificationInfo userNotification)
 {
     return(Task.FromResult(0));
 }
 /// <summary>
 /// 插入用户通知-异步
 /// </summary>
 /// <param name="userNotification">用户通知</param>
 /// <returns></returns>
 public Task InsertUserNotificationAsync(UserNotificationInfo userNotification)
 {
     return Task.FromResult(0);
 }
        protected virtual async Task<List<UserNotification>> SaveUserNotifications(UserIdentifier[] users, NotificationInfo notificationInfo)
        {
            var userNotifications = new List<UserNotification>();

            var tenantGroups = users.GroupBy(user => user.TenantId);
            foreach (var tenantGroup in tenantGroups)
            {
                using (_unitOfWorkManager.Current.SetTenantId(tenantGroup.Key))
                {
                    var tenantNotificationInfo = new TenantNotificationInfo(tenantGroup.Key, notificationInfo);
                    await _notificationStore.InsertTenantNotificationAsync(tenantNotificationInfo);
                    await _unitOfWorkManager.Current.SaveChangesAsync(); //To get tenantNotification.Id.

                    var tenantNotification = tenantNotificationInfo.ToTenantNotification();

                    foreach (var user in tenantGroup)
                    {
                        var userNotification = new UserNotificationInfo
                        {
                            TenantId = tenantGroup.Key,
                            UserId = user.UserId,
                            TenantNotificationId = tenantNotificationInfo.Id
                        };

                        await _notificationStore.InsertUserNotificationAsync(userNotification);
                        userNotifications.Add(userNotification.ToUserNotification(tenantNotification));
                    }

                    await CurrentUnitOfWork.SaveChangesAsync(); //To get Ids of the notifications
                }
            }

            return userNotifications;
        }
 public virtual Task InsertUserNotificationAsync(UserNotificationInfo userNotification)
 {
     return _userNotificationRepository.InsertAsync(userNotification);
 }
 public void InsertUserNotification(UserNotificationInfo userNotification)
 {
 }
Exemple #10
0
 public virtual Task InsertUserNotificationAsync(UserNotificationInfo userNotification)
 {
     return(_userNotificationRepository.InsertAsync(userNotification));
 }