@@ -27,17 +27,40 @@ protected override async Task<UpdateRosterEmail> CreateEmail(HandlerContext<Comm
2727 UpdateRosterEmail_State . MatchHeadType matchHead ;
2828 if ( roster . BitsMatchId != 0 )
2929 {
30- Bits_VMatchHeadInfo matchHeadInfo = await context . Databases . Bits . VMatchHeadInfo . SingleAsync (
30+ Bits_VMatchHeadInfo ? matchHeadInfo = await context . Databases . Bits . VMatchHeadInfo . SingleOrDefaultAsync (
3131 x => x . ExternalMatchId == roster . BitsMatchId ) ;
32- matchHead = new (
33- "Hemmalag" ,
34- matchHeadInfo . HomeTeamAlias ,
35- "Bortalag" ,
36- matchHeadInfo . AwayTeamAlias ,
37- matchHeadInfo . HallName ,
38- matchHeadInfo . OilProfileId ,
39- matchHeadInfo . OilProfileName ,
40- matchHeadInfo . MatchDateTime ) ;
32+ if ( matchHeadInfo is not null )
33+ {
34+ matchHead = new (
35+ "Hemmalag" ,
36+ matchHeadInfo . HomeTeamAlias ,
37+ "Bortalag" ,
38+ matchHeadInfo . AwayTeamAlias ,
39+ matchHeadInfo . HallName ,
40+ matchHeadInfo . OilProfileId ,
41+ matchHeadInfo . OilProfileName ,
42+ matchHeadInfo . MatchDateTime ) ;
43+ }
44+ else
45+ {
46+ int oilPatternId = 0 ;
47+ if ( roster . OilPattern is not null )
48+ {
49+ int . TryParse (
50+ roster . OilPattern . Url . Substring ( roster . OilPattern . Url . LastIndexOf ( '/' ) + 1 ) ,
51+ out oilPatternId ) ;
52+ }
53+
54+ matchHead = new (
55+ "Lag" ,
56+ roster . Team ?? "?" ,
57+ "Motståndare" ,
58+ roster . Opponent ?? "?" ,
59+ roster . Location ?? "?" ,
60+ oilPatternId == 0 ? null : oilPatternId ,
61+ roster . OilPattern ? . Name ?? "Ingen oljeprofil" ,
62+ roster . Date ) ;
63+ }
4164 }
4265 else
4366 {
0 commit comments