Example #1
0
        public async Task HandleEventAsync(EntityCreatedEventData <UserEto> eventData)
        {
            // 获取默认语言
            var userDefaultCultureName = await _settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage);

            if (userDefaultCultureName.IsNullOrWhiteSpace())
            {
                userDefaultCultureName = CultureInfo.CurrentUICulture.Name;
                // CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(userDefaultCultureName);
            }
            using (CultureHelper.Use(userDefaultCultureName, userDefaultCultureName))
            {
                var userIdentifer = new UserIdentifier(eventData.Entity.Id, eventData.Entity.UserName);
                // 订阅用户欢迎消息
                await _notificationSubscriptionManager.SubscribeAsync(eventData.Entity.TenantId,
                                                                      userIdentifer, UserNotificationNames.WelcomeToApplication);

                // Store未检查已订阅
                //await _notificationStore.InsertUserSubscriptionAsync(eventData.Entity.TenantId,
                //    userIdentifer, UserNotificationNames.WelcomeToApplication);

                var userWelcomeNotifictionData = NotificationData.CreateUserNotificationData(eventData.Entity.Id, eventData.Entity.UserName);

                userWelcomeNotifictionData.WriteStandardData(
                    L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName),
                    L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName),
                    DateTime.Now, eventData.Entity.UserName);

                // 换成用户名称,而不是用户名
                // userWelcomeNotifictionData.Properties["message"] = L("WelcomeToApplicationFormUser", eventData.Entity.Name);

                var noticeNormalizerName = NotificationNameNormalizer.NormalizerName(UserNotificationNames.WelcomeToApplication);
                await _notificationDispatcher.DispatchAsync(noticeNormalizerName, userWelcomeNotifictionData, eventData.Entity.TenantId);
            }
        }