1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using JoinRpg . Data . Interfaces ;
5- using JoinRpg . Data . Interfaces . Subscribe ;
6- using JoinRpg . DataModel ;
7- using JoinRpg . Services . Interfaces ;
8-
91namespace JoinRpg . Web . Models . Subscribe
102{
113 public class SubscribeListViewModel
@@ -19,90 +11,4 @@ public class SubscribeListViewModel
1911
2012 public int ProjectId { get ; set ; }
2113 }
22-
23- public interface ISubscribeTarget : ILinkable
24- {
25- public string Name { get ; }
26- }
27-
28- public static class Builders
29- {
30- public static SubscribeListViewModel ToSubscribeListViewModel (
31- this ( User User , UserSubscriptionDto [ ] UserSubscriptions ) data ,
32- User currentUser ,
33- IUriService uriService ,
34- int projectId ,
35- List < PaymentTypeDto > paymentTypes )
36- {
37- return new SubscribeListViewModel ( )
38- {
39- User = new UserProfileDetailsViewModel ( data . User , currentUser ) ,
40- AllowChanges = data . User == currentUser , //TODO allow project admins to setup subscribe for other masters
41- Items = data . UserSubscriptions . Select ( x => x . ToViewModel ( uriService ) ) . ToArray ( ) ,
42- ProjectId = projectId ,
43- PaymentTypeNames = paymentTypes . Select ( pt => pt . ToPaymentTypeName ( ) ) . ToArray ( ) ,
44- } ;
45- }
46-
47- private static string ToPaymentTypeName ( this PaymentTypeDto dto )
48- {
49- return dto . TypeKind switch
50- {
51- PaymentTypeKind . Custom => dto . Name ,
52- PaymentTypeKind . Cash => "Наличные" ,
53- PaymentTypeKind . Online => "Онлайн" ,
54- _ => throw new ArgumentOutOfRangeException ( "dto.TypeKind" , ( object ) dto . TypeKind , "Wrong type" ) ,
55- } ;
56- }
57-
58- private class AbstractLinkable : ISubscribeTarget
59- {
60- public LinkType LinkType { get ; set ; }
61-
62- public string Identification { get ; set ; }
63-
64- public int ? ProjectId { get ; set ; }
65-
66- public string Name { get ; set ; }
67- }
68-
69- public static SubscribeListItemViewModel ToViewModel ( this UserSubscriptionDto dto , IUriService uriService )
70- {
71- var link = dto . ToSubscribeTargetLink ( ) ;
72- return new SubscribeListItemViewModel
73- {
74- Name = link . Name ,
75- Link = uriService . GetUri ( link ) ,
76- UserSubscriptionId = dto . UserSubscriptionId ,
77- Options = new SubscribeOptionsViewModel ( )
78- {
79- AccommodationChange = dto . Options . AccommodationChange ,
80- ClaimStatusChange = dto . Options . ClaimStatusChange ,
81- Comments = dto . Options . Comments ,
82- FieldChange = dto . Options . FieldChange ,
83- MoneyOperation = dto . Options . MoneyOperation ,
84- } ,
85- } ;
86- }
87-
88- public static ISubscribeTarget ToSubscribeTargetLink ( this UserSubscriptionDto dto )
89- {
90- ( LinkType type , string name , int id ) link = dto switch
91- {
92- { CharacterId : int id , CharacterNames : string name } => ( LinkType . ResultCharacter , name , id ) ,
93- { CharacterGroupId : int id , CharacterGroupName : string name } => ( LinkType . ResultCharacterGroup , name , id ) ,
94- { ClaimId : int id , ClaimName : string name } => ( LinkType . Claim , name , id ) ,
95- _ => throw new InvalidOperationException ( ) ,
96- } ;
97-
98- return new AbstractLinkable
99- {
100- LinkType = link . type ,
101- Identification = link . id . ToString ( ) ,
102- ProjectId = dto . ProjectId ,
103- Name = link . name ,
104- } ;
105- }
106-
107- }
10814}
0 commit comments