File tree Expand file tree Collapse file tree
src/Services/Marketing/Marketing.API/Model Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ namespace Microsoft . eShopOnContainers . Services . Marketing . API . Model
2+ {
3+ using Microsoft . eShopOnContainers . Services . Marketing . API . Infrastructure . Exceptions ;
4+ using System ;
5+ using System . Collections . Generic ;
6+ using System . Linq ;
7+
8+ public sealed class RuleType
9+ {
10+ public static readonly RuleType UserProfileRule = new RuleType ( 1 , nameof ( UserProfileRule ) ) ;
11+ public static readonly RuleType PurchaseHistoryRule = new RuleType ( 2 , nameof ( UserProfileRule ) ) ;
12+ public static readonly RuleType UserLocationRule = new RuleType ( 3 , nameof ( UserProfileRule ) ) ;
13+
14+ public readonly int Id ;
15+ public readonly string Name ;
16+
17+ private RuleType ( int id , string name )
18+ {
19+ Id = id ;
20+ Name = name ;
21+ }
22+
23+ public static IEnumerable < RuleType > List ( ) =>
24+ new [ ] { UserProfileRule , PurchaseHistoryRule , UserLocationRule } ;
25+
26+ public static RuleType FromName ( string name )
27+ {
28+ var state = List ( )
29+ . SingleOrDefault ( s => String . Equals ( s . Name , name , StringComparison . CurrentCultureIgnoreCase ) ) ;
30+
31+ if ( state == null )
32+ {
33+ throw new MarketingDomainException ( $ "Possible values for RuleType: { String . Join ( "," , List ( ) . Select ( s => s . Name ) ) } ") ;
34+ }
35+
36+ return state ;
37+ }
38+
39+ public static RuleType From ( int id )
40+ {
41+ var state = List ( ) . SingleOrDefault ( s => s . Id == id ) ;
42+
43+ if ( state == null )
44+ {
45+ throw new MarketingDomainException ( $ "Possible values for RuleType: { String . Join ( "," , List ( ) . Select ( s => s . Name ) ) } ") ;
46+ }
47+
48+ return state ;
49+ }
50+ }
51+ }
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments