@@ -35,12 +35,13 @@ public class RentalListingReportService : ServiceBase, IRentalListingReportServi
35
35
private IEmailMessageService _emailService ;
36
36
private IEmailMessageRepository _emailRepo ;
37
37
private IBizLicenceRepository _bizLicRepo ;
38
+ private IPermitValidationService _permitValidation ;
38
39
private IConfiguration _config ;
39
40
40
41
public RentalListingReportService ( ICurrentUser currentUser , IFieldValidatorService validator , IUnitOfWork unitOfWork , IMapper mapper , IHttpContextAccessor httpContextAccessor ,
41
42
IOrganizationRepository orgRepo , IUploadDeliveryRepository uploadRepo , IRentalListingReportRepository reportRepo , IPhysicalAddressRepository addressRepo ,
42
43
IGeocoderApi geocoder , IUserRepository userRepo , IEmailMessageService emailService , IEmailMessageRepository emailRepo , IBizLicenceRepository bizLicRepo ,
43
- IConfiguration config , ILogger < StrDssLogger > logger )
44
+ IPermitValidationService permitValidation , IConfiguration config , ILogger < StrDssLogger > logger )
44
45
: base ( currentUser , validator , unitOfWork , mapper , httpContextAccessor , logger )
45
46
{
46
47
_orgRepo = orgRepo ;
@@ -52,6 +53,7 @@ public RentalListingReportService(ICurrentUser currentUser, IFieldValidatorServi
52
53
_emailService = emailService ;
53
54
_emailRepo = emailRepo ;
54
55
_bizLicRepo = bizLicRepo ;
56
+ _permitValidation = permitValidation ;
55
57
_config = config ;
56
58
}
57
59
@@ -216,6 +218,17 @@ private async Task<bool> ProcessUploadLine(DssRentalListingReport report, DssUpl
216
218
return false ;
217
219
}
218
220
221
+ // Should we validate the Registration?
222
+ bool isRegistrationValid = false ;
223
+ if ( _currentUser . Permissions . Any ( p => p == Permissions . ValidateRegistration ) )
224
+ {
225
+ // Do we have what we need to validate the registration?
226
+ if ( ! string . IsNullOrEmpty ( row . RegNo ) && ! string . IsNullOrEmpty ( row . RentalStreet ) && ! string . IsNullOrEmpty ( row . RentalPostal ) )
227
+ {
228
+ ( isRegistrationValid , Dictionary < string , List < string > > regErrors ) = await _permitValidation . ValidateRegistrationPermitAsync ( row . RegNo , row . RentalUnit , row . RentalStreet , row . RentalPostal ) ;
229
+ }
230
+ }
231
+
219
232
var offeringOrg = await _orgRepo . GetOrganizationByOrgCdAsync ( row . OrgCd ) ; //already validated in the file upload
220
233
221
234
using var tran = _unitOfWork . BeginTransaction ( ) ;
@@ -224,7 +237,7 @@ private async Task<bool> ProcessUploadLine(DssRentalListingReport report, DssUpl
224
237
225
238
AddContacts ( listing , row ) ;
226
239
227
- var ( physicalAddress , systemError ) = await CreateOrGetPhysicalAddress ( listing , row ) ;
240
+ var ( physicalAddress , systemError ) = await CreateOrGetPhysicalAddress ( listing , row , isRegistrationValid ) ;
228
241
229
242
listing . LocatingPhysicalAddress = physicalAddress ;
230
243
@@ -262,6 +275,8 @@ private async Task<bool> ProcessUploadLine(DssRentalListingReport report, DssUpl
262
275
}
263
276
264
277
tran . Commit ( ) ;
278
+
279
+
265
280
return true ;
266
281
}
267
282
@@ -300,7 +315,7 @@ private async Task<DssRentalListing> CreateOrUpdateRentalListing(DssRentalListin
300
315
return listing ;
301
316
}
302
317
303
- private async Task < ( DssPhysicalAddress , string ) > CreateOrGetPhysicalAddress ( DssRentalListing listing , RentalListingRowUntyped row )
318
+ private async Task < ( DssPhysicalAddress , string ) > CreateOrGetPhysicalAddress ( DssRentalListing listing , RentalListingRowUntyped row , bool isRegistrationValid )
304
319
{
305
320
var address = row . RentalAddress ;
306
321
@@ -312,10 +327,7 @@ private async Task<DssRentalListing> CreateOrUpdateRentalListing(DssRentalListin
312
327
{
313
328
var newAddress = new DssPhysicalAddress
314
329
{
315
- OriginalAddressTxt = row . RentalAddress ,
316
- RegRentalUnitNo = row . RentalUnit ,
317
- RegRentalStreetNo = row . RentalStreet ,
318
- RegRentalPostalCode = row . RentalPostal ,
330
+ OriginalAddressTxt = row . RentalAddress
319
331
} ;
320
332
321
333
error = await _geocoder . GetAddressAsync ( newAddress ) ;
@@ -350,9 +362,12 @@ private async Task<DssRentalListing> CreateOrUpdateRentalListing(DssRentalListin
350
362
351
363
listing . IsChangedOriginalAddress = true ;
352
364
353
- newAddress . RegRentalUnitNo = row . RentalUnit ;
354
- newAddress . RegRentalStreetNo = row . RentalStreet ;
355
- newAddress . RegRentalPostalCode = row . RentalPostal ;
365
+ if ( isRegistrationValid )
366
+ {
367
+ newAddress . RegRentalUnitNo = row . RentalUnit ;
368
+ newAddress . RegRentalStreetNo = row . RentalStreet ;
369
+ newAddress . RegRentalPostalCode = row . RentalPostal ;
370
+ }
356
371
357
372
_addressRepo . ReplaceAddress ( listing , newAddress ) ;
358
373
@@ -363,12 +378,16 @@ private async Task<DssRentalListing> CreateOrUpdateRentalListing(DssRentalListin
363
378
{
364
379
var newAddress = new DssPhysicalAddress
365
380
{
366
- OriginalAddressTxt = row . RentalAddress ,
367
- RegRentalUnitNo = row . RentalUnit ,
368
- RegRentalStreetNo = row . RentalStreet ,
369
- RegRentalPostalCode = row . RentalPostal ,
381
+ OriginalAddressTxt = row . RentalAddress
370
382
} ;
371
383
384
+ if ( isRegistrationValid )
385
+ {
386
+ newAddress . RegRentalUnitNo = row . RentalUnit ;
387
+ newAddress . RegRentalStreetNo = row . RentalStreet ;
388
+ newAddress . RegRentalPostalCode = row . RentalPostal ;
389
+ }
390
+
372
391
error = await _geocoder . GetAddressAsync ( newAddress ) ;
373
392
374
393
if ( error . IsEmpty ( ) && newAddress . LocationGeometry is not null && newAddress . LocationGeometry is Point point )
0 commit comments