4
4
5
5
namespace Core . Mappers ;
6
6
7
- public class UserPreferencesMapper
7
+ public static class UserPreferencesMapper
8
8
{
9
9
internal static UserPreferencesDto ToDto ( UserPreferences e )
10
10
{
@@ -17,44 +17,41 @@ internal static UserPreferencesDto ToDto(UserPreferences e)
17
17
Enabled = d . Value . Enabled ,
18
18
Description = d . Value . Description ,
19
19
Metadata = d . Value . Metadata
20
- } ) ?? [ ]
20
+ } )
21
21
} ;
22
22
}
23
23
24
24
public static UserPreferences UpdateEntity ( UserPreferences e , UserPreferencesDto dto )
25
25
{
26
26
var channels = e . Channels ;
27
- if ( channels . Count > 0 )
27
+ foreach ( var ch in dto . Channels )
28
28
{
29
- foreach ( var ch in dto . Channels )
29
+ if ( channels . TryGetValue ( ch . Key , out var channel ) )
30
30
{
31
- if ( channels . TryGetValue ( ch . Key , out var channel ) )
32
- {
33
- channel . Enabled = ch . Value . Enabled ;
34
- channel . Description = ch . Value . Description ;
35
- channel . Metadata = ch . Value . Metadata ;
36
- }
37
- else
31
+ channel . Enabled = ch . Value . Enabled ;
32
+ channel . Description = ch . Value . Description ;
33
+ channel . Metadata = ch . Value . Metadata ;
34
+ }
35
+ else
36
+ {
37
+ channels . Add ( ch . Key , new ChannelDescriptorBase
38
38
{
39
- channels . Add ( ch . Key , new ChannelDescriptorBase
40
- {
41
- Enabled = ch . Value . Enabled ,
42
- Description = ch . Value . Description ,
43
- Metadata = ch . Value . Metadata
44
- } ) ;
45
- }
39
+ Enabled = ch . Value . Enabled ,
40
+ Description = ch . Value . Description ,
41
+ Metadata = ch . Value . Metadata
42
+ } ) ;
46
43
}
47
44
}
48
-
45
+
49
46
return e with { LastUpdated = DateTimeOffset . UtcNow , Channels = channels } ;
50
47
}
51
-
48
+
52
49
public static UserPreferences ToEntity ( UserPreferencesDto dto )
53
50
{
54
51
var id = string . IsNullOrEmpty ( dto . Id )
55
52
? ObjectId . GenerateNewId ( )
56
53
: ObjectId . Parse ( dto . Id ) ;
57
-
54
+
58
55
return new UserPreferences
59
56
{
60
57
Id = id ,
0 commit comments