1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using Abp . AspNetCore . Mvc . Extensions ;
3
4
using Abp . Auditing ;
5
+ using Abp . Configuration ;
4
6
using Abp . Localization ;
7
+ using Abp . Runtime . Caching ;
5
8
using Abp . Runtime . Session ;
6
9
using Abp . Timing ;
7
10
using Abp . Web . Models ;
@@ -15,10 +18,18 @@ namespace Abp.AspNetCore.Mvc.Controllers
15
18
public class AbpLocalizationController : AbpController
16
19
{
17
20
protected IUrlHelper UrlHelper ;
18
-
19
- public AbpLocalizationController ( IUrlHelper urlHelper )
21
+ private readonly ISettingStore _settingStore ;
22
+
23
+ private readonly ITypedCache < string , Dictionary < string , SettingInfo > > _userSettingCache ;
24
+
25
+ public AbpLocalizationController (
26
+ IUrlHelper urlHelper ,
27
+ ISettingStore settingStore ,
28
+ ICacheManager cacheManager )
20
29
{
21
30
UrlHelper = urlHelper ;
31
+ _settingStore = settingStore ;
32
+ _userSettingCache = cacheManager . GetUserSettingsCache ( ) ;
22
33
}
23
34
24
35
[ DisableAuditing ]
@@ -43,11 +54,7 @@ public virtual ActionResult ChangeCulture(string cultureName, string returnUrl =
43
54
44
55
if ( AbpSession . UserId . HasValue )
45
56
{
46
- SettingManager . ChangeSettingForUser (
47
- AbpSession . ToUserIdentifier ( ) ,
48
- LocalizationSettingNames . DefaultLanguage ,
49
- cultureName
50
- ) ;
57
+ ChangeCultureForUser ( cultureName ) ;
51
58
}
52
59
53
60
if ( Request . IsAjaxRequest ( ) )
@@ -69,7 +76,37 @@ public virtual ActionResult ChangeCulture(string cultureName, string returnUrl =
69
76
}
70
77
}
71
78
72
- return LocalRedirect ( "/" ) ; //TODO: Go to app root
79
+ return LocalRedirect ( "/" ) ;
80
+ }
81
+
82
+ protected virtual void ChangeCultureForUser ( string cultureName )
83
+ {
84
+ var languageSetting = _settingStore . GetSettingOrNull (
85
+ AbpSession . TenantId ,
86
+ AbpSession . GetUserId ( ) ,
87
+ LocalizationSettingNames . DefaultLanguage
88
+ ) ;
89
+
90
+ if ( languageSetting == null )
91
+ {
92
+ _settingStore . Create ( new SettingInfo (
93
+ AbpSession . TenantId ,
94
+ AbpSession . UserId ,
95
+ LocalizationSettingNames . DefaultLanguage ,
96
+ cultureName
97
+ ) ) ;
98
+ }
99
+ else
100
+ {
101
+ _settingStore . Update ( new SettingInfo (
102
+ AbpSession . TenantId ,
103
+ AbpSession . UserId ,
104
+ LocalizationSettingNames . DefaultLanguage ,
105
+ cultureName
106
+ ) ) ;
107
+ }
108
+
109
+ _userSettingCache . Remove ( AbpSession . ToUserIdentifier ( ) . ToString ( ) ) ;
73
110
}
74
111
}
75
112
}
0 commit comments