Esempio n. 1
0
 public void InsertTenantNotification(TenantNotificationInfo tenantNotificationInfo)
 {
     using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
     {
         _tenantNotificationRepository.Insert(tenantNotificationInfo);
     }
 }
 public virtual async Task InsertTenantNotificationAsync(TenantNotificationInfo tenantNotificationInfo)
 {
     using (_unitOfWorkManager.Current.SetTenantId(tenantNotificationInfo.TenantId))
     {
         await _tenantNotificationRepository.InsertAsync(tenantNotificationInfo);
     }
 }
Esempio n. 3
0
 public virtual async Task InsertTenantNotificationAsync(TenantNotificationInfo tenantNotificationInfo)
 {
     using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
     {
         await _tenantNotificationRepository.InsertAsync(tenantNotificationInfo);
     }
 }
        /// <summary>
        /// Return notification data (unwrap <see cref="ShaNotificationData"/> if needed)
        /// </summary>
        /// <returns></returns>
        protected NotificationData GetNotificationData(TenantNotificationInfo tenantNotificationInfo)
        {
            var tenantNotification = tenantNotificationInfo.ToTenantNotification();

            return(tenantNotification.Data is ShaNotificationData shaNotificationData
                ? shaNotificationData.GetData()
                : tenantNotification.Data);
        }
Esempio n. 5
0
        protected virtual async Task <List <UserNotification> > SaveUserNotificationsAsync(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);
                    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(_guidGenerator.Create())
                        {
                            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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserNotificationInfoWithNotificationInfo"/> class.
 /// </summary>
 public UserNotificationInfoWithNotificationInfo(UserNotificationInfo userNotification, TenantNotificationInfo notification)
 {
     UserNotification = userNotification;
     Notification     = notification;
 }
        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;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserNotificationInfoWithNotificationInfo"/> class.
 /// </summary>
 public UserNotificationInfoWithNotificationInfo(UserNotificationInfo userNotification, TenantNotificationInfo notification)
 {
     UserNotification = userNotification;
     Notification = notification;
 }
 public virtual Task InsertTenantNotificationAsync(TenantNotificationInfo tenantNotificationInfo)
 {
     using (_unitOfWorkManager.Current.SetTenantId(tenantNotificationInfo.TenantId))
     {
         return _tenantNotificationRepository.InsertAsync(tenantNotificationInfo);
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserNotificationInfoWithNotificationInfo"/> class.
 /// </summary>
 public UserNotificationInfoWithNotificationInfo(UserNotificationInfo userNotification, TenantNotificationInfo notification)
 {
     this.UserNotification = userNotification;
     this.Notification     = notification;
 }
 public Task InsertTenantNotificationAsync(TenantNotificationInfo tenantNotificationInfo)
 {
     return Task.FromResult(0);
 }
Esempio n. 12
0
        protected virtual async Task <List <NotificationMessageDto> > SaveUserNotificationMessagesAsync(NotificationInfo notificationInfo)
        {
            var notificationMessages = new List <NotificationMessageDto>();

            var tenantIds = GetTenantIds(notificationInfo);

            foreach (var tenantId in tenantIds)
            {
                using (_unitOfWorkManager.Current.SetTenantId(tenantId))
                {
                    var tenantNotificationInfo = new TenantNotificationInfo(_guidGenerator.Create(), tenantId, notificationInfo);
                    await _notificationStore.InsertTenantNotificationAsync(tenantNotificationInfo);

                    await _unitOfWorkManager.Current.SaveChangesAsync(); //To get tenantNotification.Id.

                    var tenantNotification = tenantNotificationInfo.ToTenantNotification();

                    if (tenantNotification.Data is ShaNotificationData shaData)
                    {
                        await _notificationStore.InsertTenantNotificationAsync(tenantNotificationInfo);

                        await _unitOfWorkManager.Current.SaveChangesAsync(); //To get tenantNotification.Id.

                        var notificationMessage = new NotificationMessage
                        {
                            TenantNotification = tenantNotificationInfo,
                            SendType           = shaData.SendType,
                            RecipientText      = shaData.RecipientText,
                            Status             = RefListNotificationStatus.Preparing
                        };
                        await _messageRepository.InsertAsync(notificationMessage);

                        var notificationMessageDto = ObjectMapper.Map <NotificationMessageDto>(notificationMessage);

                        // save attachments if specified
                        if (shaData.Attachments != null)
                        {
                            foreach (var attachmentDto in shaData.Attachments)
                            {
                                var file = await _storedFileRepository.GetAsync(attachmentDto.StoredFileId);

                                var attachment = new NotificationMessageAttachment
                                {
                                    Message  = notificationMessage,
                                    File     = file,
                                    FileName = attachmentDto.FileName
                                };
                                await _attachmentRepository.InsertAsync(attachment);

                                notificationMessageDto.Attachments.Add(ObjectMapper.Map <NotificationAttachmentDto>(attachment));
                            }
                        }

                        notificationMessages.Add(notificationMessageDto);

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

            return(notificationMessages);
        }