@@ -49,48 +49,84 @@ public async Task<Call> GenerateCall(CallEmail email, string managingUser, List<
4949 if ( String . IsNullOrEmpty ( email . Subject ) )
5050 return null ;
5151
52- string [ ] sections = email . TextBody . Split ( new [ ] { " ALPHA 512 " } , StringSplitOptions . None ) ;
53- string [ ] sectionOneParts = sections [ 0 ] . Split ( new [ ] { " " } , StringSplitOptions . None ) ;
54-
55- Call c = new Call ( ) ;
56- c . Notes = email . TextBody ;
57- c . Name = sections [ 1 ] . Trim ( ) ;
58- c . LoggedOn = DateTime . UtcNow ;
59- c . Priority = priority ;
60- c . ReportingUserId = managingUser ;
61- c . Dispatches = new Collection < CallDispatch > ( ) ;
62- c . CallSource = ( int ) CallSources . EmailImport ;
63- c . SourceIdentifier = email . MessageId ;
64- c . NatureOfCall = sections [ 1 ] . Trim ( ) ;
65- c . IncidentNumber = sectionOneParts [ 0 ] . Trim ( ) ;
66- c . ExternalIdentifier = sectionOneParts [ 0 ] . Trim ( ) ;
67-
68- if ( users != null && users . Any ( ) )
52+ try
6953 {
70- foreach ( var u in users )
54+ string [ ] sections = email . TextBody . Split ( new [ ] { " ALPHA 512 " } , StringSplitOptions . None ) ;
55+ string [ ] sectionOneParts = sections [ 0 ] . Split ( new [ ] { " " } , StringSplitOptions . None ) ;
56+
57+ Call c = new Call ( ) ;
58+ c . Notes = email . TextBody ;
59+ c . Name = sections [ 1 ] . Trim ( ) ;
60+ c . LoggedOn = DateTime . UtcNow ;
61+ c . Priority = priority ;
62+ c . ReportingUserId = managingUser ;
63+ c . Dispatches = new Collection < CallDispatch > ( ) ;
64+ c . CallSource = ( int ) CallSources . EmailImport ;
65+ c . SourceIdentifier = email . MessageId ;
66+ c . NatureOfCall = sections [ 1 ] . Trim ( ) ;
67+ c . IncidentNumber = sectionOneParts [ 0 ] . Trim ( ) ;
68+ c . ExternalIdentifier = sectionOneParts [ 0 ] . Trim ( ) ;
69+
70+ if ( users != null && users . Any ( ) )
7171 {
72- CallDispatch cd = new CallDispatch ( ) ;
73- cd . UserId = u . UserId ;
72+ foreach ( var u in users )
73+ {
74+ CallDispatch cd = new CallDispatch ( ) ;
75+ cd . UserId = u . UserId ;
7476
75- c . Dispatches . Add ( cd ) ;
77+ c . Dispatches . Add ( cd ) ;
78+ }
7679 }
77- }
7880
79- // Search for an active call
80- if ( activeCalls != null && activeCalls . Any ( ) )
81+ // Search for an active call
82+ if ( activeCalls != null && activeCalls . Any ( ) )
83+ {
84+ var activeCall = activeCalls . FirstOrDefault ( x => x . IncidentNumber == c . IncidentNumber ) ;
85+
86+ if ( activeCall != null )
87+ {
88+ activeCall . Notes = c . Notes ;
89+ activeCall . LastDispatchedOn = DateTime . UtcNow ;
90+
91+ return activeCall ;
92+ }
93+ }
94+
95+ return c ;
96+ }
97+ catch ( Exception ex )
8198 {
82- var activeCall = activeCalls . FirstOrDefault ( x => x . IncidentNumber == c . IncidentNumber ) ;
99+ Call c = new Call ( ) ;
100+ c . Name = email . Subject ;
101+ c . NatureOfCall = $ "ERROR PROCESSING DISPATCH EMAIL, Unprocessed email body: { email . TextBody } ";
83102
84- if ( activeCall != null )
103+ if ( users != null && users . Any ( ) )
85104 {
86- activeCall . Notes = c . Notes ;
87- activeCall . LastDispatchedOn = DateTime . UtcNow ;
105+ foreach ( var u in users )
106+ {
107+ CallDispatch cd = new CallDispatch ( ) ;
108+ cd . UserId = u . UserId ;
88109
89- return activeCall ;
110+ c . Dispatches . Add ( cd ) ;
111+ }
90112 }
91- }
92113
93- return c ;
114+ // Search for an active call
115+ if ( activeCalls != null && activeCalls . Any ( ) )
116+ {
117+ var activeCall = activeCalls . FirstOrDefault ( x => x . IncidentNumber == c . IncidentNumber ) ;
118+
119+ if ( activeCall != null )
120+ {
121+ activeCall . Notes = c . Notes ;
122+ activeCall . LastDispatchedOn = DateTime . UtcNow ;
123+
124+ return activeCall ;
125+ }
126+ }
127+
128+ return c ;
129+ }
94130 }
95131 }
96132}
0 commit comments