/// <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 }); }
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 Task InsertTenantNotificationAsync(TenantNotificationInfo tenantNotificationInfo) { return(Task.FromResult(0)); }