2525
2626namespace BackendConfiguration . Pn . Handlers ;
2727
28- public class WorkOrderCreatedHandler : IHandleMessages < WorkOrderCreated >
28+ public class WorkOrderCreatedHandler (
29+ BackendConfigurationDbContextHelper backendConfigurationDbContextHelper ,
30+ ChemicalDbContextHelper chemicalDbContextHelper ,
31+ Core sdkCore ,
32+ IBackendConfigurationLocalizationService backendConfigurationLocalizationService )
33+ : IHandleMessages < WorkOrderCreated >
2934{
30- private readonly Core _sdkCore ;
31- private readonly BackendConfigurationDbContextHelper _backendConfigurationDbContextHelper ;
32- private readonly ChemicalDbContextHelper _chemicalDbContextHelper ;
33- private readonly IBackendConfigurationLocalizationService _backendConfigurationLocalizationService ;
34-
35- public WorkOrderCreatedHandler ( BackendConfigurationDbContextHelper backendConfigurationDbContextHelper , ChemicalDbContextHelper chemicalDbContextHelper , Core sdkCore , IBackendConfigurationLocalizationService backendConfigurationLocalizationService )
36- {
37- _backendConfigurationDbContextHelper = backendConfigurationDbContextHelper ;
38- _chemicalDbContextHelper = chemicalDbContextHelper ;
39- _sdkCore = sdkCore ;
40- _backendConfigurationLocalizationService = backendConfigurationLocalizationService ;
41- }
35+ private readonly ChemicalDbContextHelper _chemicalDbContextHelper = chemicalDbContextHelper ;
4236
4337 public async Task Handle ( WorkOrderCreated message )
4438 {
@@ -89,8 +83,8 @@ private async Task DeployEform(
8983 List < KeyValuePair < string , string > > picturesOfTasks
9084 )
9185 {
92- var backendConfigurationPnDbContext = _backendConfigurationDbContextHelper . GetDbContext ( ) ;
93- var sdkDbContext = _sdkCore . DbContextHelper . GetDbContext ( ) ;
86+ var backendConfigurationPnDbContext = backendConfigurationDbContextHelper . GetDbContext ( ) ;
87+ var sdkDbContext = sdkCore . DbContextHelper . GetDbContext ( ) ;
9488
9589 var workOrderCase = await backendConfigurationPnDbContext . WorkorderCases . FirstAsync ( x => x . Id == workorderCaseId ) ;
9690 DateTime startDate = new DateTime ( 2022 , 12 , 5 ) ;
@@ -108,19 +102,19 @@ List<KeyValuePair<string, string>> picturesOfTasks
108102 {
109103 case "1" :
110104 displayOrder = 100_000_000 + displayOrder ;
111- priorityText = $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "Priority" ) } :</strong> { _backendConfigurationLocalizationService . GetString ( "Urgent" ) } <br>";
105+ priorityText = $ "<strong>{ backendConfigurationLocalizationService . GetString ( "Priority" ) } :</strong> { backendConfigurationLocalizationService . GetString ( "Urgent" ) } <br>";
112106 break ;
113107 case "2" :
114108 displayOrder = 200_000_000 + displayOrder ;
115- priorityText = $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "Priority" ) } :</strong> { _backendConfigurationLocalizationService . GetString ( "High" ) } <br>";
109+ priorityText = $ "<strong>{ backendConfigurationLocalizationService . GetString ( "Priority" ) } :</strong> { backendConfigurationLocalizationService . GetString ( "High" ) } <br>";
116110 break ;
117111 case "3" :
118112 displayOrder = 300_000_000 + displayOrder ;
119- priorityText = $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "Priority" ) } :</strong> { _backendConfigurationLocalizationService . GetString ( "Medium" ) } <br>";
113+ priorityText = $ "<strong>{ backendConfigurationLocalizationService . GetString ( "Priority" ) } :</strong> { backendConfigurationLocalizationService . GetString ( "Medium" ) } <br>";
120114 break ;
121115 case "4" :
122116 displayOrder = 400_000_000 + displayOrder ;
123- priorityText = $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "Priority" ) } :</strong> { _backendConfigurationLocalizationService . GetString ( "Low" ) } <br>";
117+ priorityText = $ "<strong>{ backendConfigurationLocalizationService . GetString ( "Priority" ) } :</strong> { backendConfigurationLocalizationService . GetString ( "Low" ) } <br>";
124118 break ;
125119 }
126120
@@ -129,37 +123,37 @@ List<KeyValuePair<string, string>> picturesOfTasks
129123 switch ( workOrderCase . CaseStatusesEnum )
130124 {
131125 case CaseStatusesEnum . Ongoing :
132- textStatus = _backendConfigurationLocalizationService . GetString ( "Ongoing" ) ;
126+ textStatus = backendConfigurationLocalizationService . GetString ( "Ongoing" ) ;
133127 break ;
134128 case CaseStatusesEnum . Completed :
135- textStatus = _backendConfigurationLocalizationService . GetString ( "Completed" ) ;
129+ textStatus = backendConfigurationLocalizationService . GetString ( "Completed" ) ;
136130 break ;
137131 case CaseStatusesEnum . Awaiting :
138- textStatus = _backendConfigurationLocalizationService . GetString ( "Awaiting" ) ;
132+ textStatus = backendConfigurationLocalizationService . GetString ( "Awaiting" ) ;
139133 break ;
140134 case CaseStatusesEnum . Ordered :
141- textStatus = _backendConfigurationLocalizationService . GetString ( "Ordered" ) ;
135+ textStatus = backendConfigurationLocalizationService . GetString ( "Ordered" ) ;
142136 break ;
143137 }
144138
145- var assignedTo = site . Name == assignedToSite . Name ? "" : $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "AssignedTo" ) } :</strong> { assignedToSite . Name } <br>";
139+ var assignedTo = site . Name == assignedToSite . Name ? "" : $ "<strong>{ backendConfigurationLocalizationService . GetString ( "AssignedTo" ) } :</strong> { assignedToSite . Name } <br>";
146140
147141 var areaName = ! string . IsNullOrEmpty ( workOrderCase . SelectedAreaName )
148- ? $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "Area" ) } :</strong> { workOrderCase . SelectedAreaName } <br>"
142+ ? $ "<strong>{ backendConfigurationLocalizationService . GetString ( "Area" ) } :</strong> { workOrderCase . SelectedAreaName } <br>"
149143 : "" ;
150144
151- var outerDescription = $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "Location" ) } :</strong> { propertyName } <br>" +
145+ var outerDescription = $ "<strong>{ backendConfigurationLocalizationService . GetString ( "Location" ) } :</strong> { propertyName } <br>" +
152146 areaName +
153- $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "Description" ) } :</strong> { newDescription } <br>" +
147+ $ "<strong>{ backendConfigurationLocalizationService . GetString ( "Description" ) } :</strong> { newDescription } <br>" +
154148 priorityText +
155- $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "CreatedBy" ) } :</strong> { workOrderCase . CreatedByName } <br>" +
149+ $ "<strong>{ backendConfigurationLocalizationService . GetString ( "CreatedBy" ) } :</strong> { workOrderCase . CreatedByName } <br>" +
156150 ( ! string . IsNullOrEmpty ( workOrderCase . CreatedByText )
157- ? $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "CreatedBy" ) } :</strong> { workOrderCase . CreatedByText } <br>"
151+ ? $ "<strong>{ backendConfigurationLocalizationService . GetString ( "CreatedBy" ) } :</strong> { workOrderCase . CreatedByText } <br>"
158152 : "" ) +
159153 assignedTo +
160- $ "<strong>{ _backendConfigurationLocalizationService . GetString ( "Status" ) } :</strong> { textStatus } <br><br>";
154+ $ "<strong>{ backendConfigurationLocalizationService . GetString ( "Status" ) } :</strong> { textStatus } <br><br>";
161155
162- var mainElement = await _sdkCore . ReadeForm ( eformId , siteLanguage ) . ConfigureAwait ( false ) ;
156+ var mainElement = await sdkCore . ReadeForm ( eformId , siteLanguage ) . ConfigureAwait ( false ) ;
163157 // mainElement.CheckListFolderName = await sdkDbContext.Folders
164158 // .Where(x => x.Id == folderId)
165159 // .Select(x => x.MicrotingUid.ToString())
@@ -233,16 +227,16 @@ List<KeyValuePair<string, string>> picturesOfTasks
233227 foreach ( var picture in picturesOfTasks )
234228 {
235229 var showPicture = new ShowPicture ( j , false , false , "" , "" , "" , 0 , false , "" ) ;
236- var storageResult = _sdkCore . GetFileFromS3Storage ( picture . Key ) . GetAwaiter ( ) . GetResult ( ) ;
230+ var storageResult = sdkCore . GetFileFromS3Storage ( picture . Key ) . GetAwaiter ( ) . GetResult ( ) ;
237231
238- await _sdkCore . PngUpload ( storageResult . ResponseStream , picture . Value , picture . Key ) ;
232+ await sdkCore . PngUpload ( storageResult . ResponseStream , picture . Value , picture . Key ) ;
239233 showPicture . Value = picture . Value ;
240234 ( ( DataElement ) mainElement . ElementList [ 0 ] ) . DataItemList . Add ( showPicture ) ;
241235 j ++ ;
242236 }
243237 }
244238 }
245- var caseId = await _sdkCore . CaseCreate ( mainElement , "" , ( int ) site . MicrotingUid ! , folderId ) . ConfigureAwait ( false ) ;
239+ var caseId = await sdkCore . CaseCreate ( mainElement , "" , ( int ) site . MicrotingUid ! , folderId ) . ConfigureAwait ( false ) ;
246240 var newWorkOrderCase = new WorkorderCase
247241 {
248242 CaseId = ( int ) caseId ! ,
@@ -259,7 +253,8 @@ List<KeyValuePair<string, string>> picturesOfTasks
259253 LastUpdatedByName = "" ,
260254 LeadingCase = false ,
261255 Priority = workOrderCase . Priority ,
262- CreatedByUserId = createdByUserId
256+ CreatedByUserId = createdByUserId ,
257+ UpdatedByUserId = createdByUserId
263258 } ;
264259 await newWorkOrderCase . Create ( backendConfigurationPnDbContext ) . ConfigureAwait ( false ) ;
265260 }
@@ -270,7 +265,7 @@ private async Task<string> InsertImage(string imageName, string itemsHtml, int i
270265 {
271266 // var filePath = Path.Combine(basePicturePath, imageName);
272267 Stream stream ;
273- var storageResult = await _sdkCore . GetFileFromS3Storage ( imageName ) . ConfigureAwait ( false ) ;
268+ var storageResult = await sdkCore . GetFileFromS3Storage ( imageName ) . ConfigureAwait ( false ) ;
274269 stream = storageResult . ResponseStream ;
275270
276271 using ( var image = new MagickImage ( stream ) )
@@ -362,14 +357,14 @@ private async Task<string> GeneratePdf(List<string> picturesOfTasks)
362357 File . Delete ( Path . Combine ( Path . GetTempPath ( ) , "reports" , "results" , docxFileName ) ) ;
363358
364359 // Upload PDF
365- string hash = await _sdkCore . PdfUpload ( tempPDFFilePath ) . ConfigureAwait ( false ) ;
360+ string hash = await sdkCore . PdfUpload ( tempPDFFilePath ) . ConfigureAwait ( false ) ;
366361 if ( hash != null )
367362 {
368363 //rename local file
369364 FileInfo fileInfo = new FileInfo ( tempPDFFilePath ) ;
370365 fileInfo . CopyTo ( downloadPath + "/" + hash + ".pdf" , true ) ;
371366 fileInfo . Delete ( ) ;
372- await _sdkCore . PutFileToStorageSystem ( Path . Combine ( downloadPath , $ "{ hash } .pdf") , $ "{ hash } .pdf") . ConfigureAwait ( false ) ;
367+ await sdkCore . PutFileToStorageSystem ( Path . Combine ( downloadPath , $ "{ hash } .pdf") , $ "{ hash } .pdf") . ConfigureAwait ( false ) ;
373368 }
374369
375370 return hash ;
0 commit comments