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 InsertTenantNotification(TenantNotificationInfo tenantNotificationInfo) { using (_unitOfWorkManager.Current.SetTenantId(tenantNotificationInfo.TenantId)) { _tenantNotificationRepository.Insert(tenantNotificationInfo); } }
public virtual async Task InsertTenantNotificationAsync(TenantNotificationInfo tenantNotificationInfo) { using (_unitOfWorkManager.Current.SetTenantId(tenantNotificationInfo.TenantId)) { await _tenantNotificationRepository.InsertAsync(tenantNotificationInfo); } }
/// <summary> /// Converts <see cref="NotificationInfo"/> to <see cref="TenantNotification"/>. /// 转换<see cref="NotificationInfo"/> 至 <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 }); }
/// <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, #pragma warning disable CS0618 // Type or member is obsolete, this line will be removed once the EntityType property is removed EntityType = entityType, #pragma warning restore CS0618 // Type or member is obsolete, this line will be removed once the EntityType property is removed EntityId = tenantNotificationInfo.EntityId.IsNullOrEmpty() ? null : JsonConvert.DeserializeObject(tenantNotificationInfo.EntityId, EntityHelper.GetPrimaryKeyType(entityType)), Severity = tenantNotificationInfo.Severity, CreationTime = tenantNotificationInfo.CreationTime }); }
public Task InsertTenantNotificationAsync(TenantNotificationInfo tenantNotificationInfo) { return(Task.FromResult(0)); }
public void InsertTenantNotification(TenantNotificationInfo tenantNotificationInfo) { }