/// <summary>
        ///     Converts <see cref="NotificationInfo" /> to <see cref="TenantNotification" />.
        /// </summary>
        public static TenantNotification ToTenantNotification(this TenantNotificationInfo tenantNotificationInfo)
        {
            var entityType = tenantNotificationInfo.EntityTypeAssemblyQualifiedName.IsNullOrEmpty()
                ? null
                : Type.GetType(tenantNotificationInfo.EntityTypeAssemblyQualifiedName);

            return(new TenantNotification
            {
                Id = tenantNotificationInfo.Id,
                TenantId = tenantNotificationInfo.TenantId,
                NotificationName = tenantNotificationInfo.NotificationName,
                Data =
                    tenantNotificationInfo.Data.IsNullOrEmpty()
                        ? null
                        : JsonConvert.DeserializeObject(tenantNotificationInfo.Data,
                                                        Type.GetType(tenantNotificationInfo.DataTypeName)) as NotificationData,
                EntityTypeName = tenantNotificationInfo.EntityTypeName,
                EntityType = entityType,
                EntityId =
                    tenantNotificationInfo.EntityId.IsNullOrEmpty()
                        ? null
                        : JsonConvert.DeserializeObject(tenantNotificationInfo.EntityId,
                                                        EntityHelper.GetPrimaryKeyType(entityType)),
                Severity = tenantNotificationInfo.Severity,
                CreationTime = tenantNotificationInfo.CreationTime
            });
        }
Example #2
0
 public virtual async Task InsertTenantNotificationAsync(TenantNotificationInfo tenantNotificationInfo)
 {
     using (unitOfWorkManager.Current.SetTenantId(tenantNotificationInfo.TenantId))
     {
         await tenantNotificationRepository.InsertAsync(tenantNotificationInfo);
     }
 }
        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(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);
        }
 public Task InsertTenantNotificationAsync(TenantNotificationInfo tenantNotificationInfo)
 {
     return(Task.FromResult(0));
 }