Skip to content

Commit 5ee4235

Browse files
committed
Listing Report Reg Validation
Added functionality to validate registry numbers from the monthly listing report upload.
1 parent 1dc2eea commit 5ee4235

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

server/StrDss.Data/Mappings/ModelToEntityProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public ModelToEntityProfile()
2323
.ForMember(dest => dest.PlatformListingNo, opt => opt.MapFrom(src => src.ListingId))
2424
.ForMember(dest => dest.PlatformListingUrl, opt => opt.MapFrom(src => src.ListingUrl))
2525
.ForMember(dest => dest.BusinessLicenceNo, opt => opt.MapFrom(src => src.BusLicNo))
26-
.ForMember(dest => dest.BcRegistryNo, opt => opt.MapFrom(src => src.BcRegNo))
26+
.ForMember(dest => dest.BcRegistryNo, opt => opt.MapFrom(src => src.RegNo))
2727
.ForMember(dest => dest.IsEntireUnit, opt => opt.MapFrom(src => src.IsEntireUnit == "Y"))
2828
.ForMember(dest => dest.AvailableBedroomsQty, opt => opt.MapFrom(src => CommonUtils.StringToShort(src.BedroomsQty)))
2929
.ForMember(dest => dest.NightsBookedQty, opt => opt.MapFrom(src => CommonUtils.StringToShort(src.NightsBookedQty)))

server/StrDss.Service/RentalListingReportService.cs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ public class RentalListingReportService : ServiceBase, IRentalListingReportServi
3535
private IEmailMessageService _emailService;
3636
private IEmailMessageRepository _emailRepo;
3737
private IBizLicenceRepository _bizLicRepo;
38+
private IPermitValidationService _permitValidation;
3839
private IConfiguration _config;
3940

4041
public RentalListingReportService(ICurrentUser currentUser, IFieldValidatorService validator, IUnitOfWork unitOfWork, IMapper mapper, IHttpContextAccessor httpContextAccessor,
4142
IOrganizationRepository orgRepo, IUploadDeliveryRepository uploadRepo, IRentalListingReportRepository reportRepo, IPhysicalAddressRepository addressRepo,
4243
IGeocoderApi geocoder, IUserRepository userRepo, IEmailMessageService emailService, IEmailMessageRepository emailRepo, IBizLicenceRepository bizLicRepo,
43-
IConfiguration config, ILogger<StrDssLogger> logger)
44+
IPermitValidationService permitValidation, IConfiguration config, ILogger<StrDssLogger> logger)
4445
: base(currentUser, validator, unitOfWork, mapper, httpContextAccessor, logger)
4546
{
4647
_orgRepo = orgRepo;
@@ -52,6 +53,7 @@ public RentalListingReportService(ICurrentUser currentUser, IFieldValidatorServi
5253
_emailService = emailService;
5354
_emailRepo = emailRepo;
5455
_bizLicRepo = bizLicRepo;
56+
_permitValidation = permitValidation;
5557
_config = config;
5658
}
5759

@@ -216,6 +218,17 @@ private async Task<bool> ProcessUploadLine(DssRentalListingReport report, DssUpl
216218
return false;
217219
}
218220

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+
219232
var offeringOrg = await _orgRepo.GetOrganizationByOrgCdAsync(row.OrgCd); //already validated in the file upload
220233

221234
using var tran = _unitOfWork.BeginTransaction();
@@ -224,7 +237,7 @@ private async Task<bool> ProcessUploadLine(DssRentalListingReport report, DssUpl
224237

225238
AddContacts(listing, row);
226239

227-
var (physicalAddress, systemError) = await CreateOrGetPhysicalAddress(listing, row);
240+
var (physicalAddress, systemError) = await CreateOrGetPhysicalAddress(listing, row, isRegistrationValid);
228241

229242
listing.LocatingPhysicalAddress = physicalAddress;
230243

@@ -262,6 +275,8 @@ private async Task<bool> ProcessUploadLine(DssRentalListingReport report, DssUpl
262275
}
263276

264277
tran.Commit();
278+
279+
265280
return true;
266281
}
267282

@@ -300,7 +315,7 @@ private async Task<DssRentalListing> CreateOrUpdateRentalListing(DssRentalListin
300315
return listing;
301316
}
302317

303-
private async Task<(DssPhysicalAddress, string)> CreateOrGetPhysicalAddress(DssRentalListing listing, RentalListingRowUntyped row)
318+
private async Task<(DssPhysicalAddress, string)> CreateOrGetPhysicalAddress(DssRentalListing listing, RentalListingRowUntyped row, bool isRegistrationValid)
304319
{
305320
var address = row.RentalAddress;
306321

@@ -312,10 +327,7 @@ private async Task<DssRentalListing> CreateOrUpdateRentalListing(DssRentalListin
312327
{
313328
var newAddress = new DssPhysicalAddress
314329
{
315-
OriginalAddressTxt = row.RentalAddress,
316-
RegRentalUnitNo = row.RentalUnit,
317-
RegRentalStreetNo = row.RentalStreet,
318-
RegRentalPostalCode = row.RentalPostal,
330+
OriginalAddressTxt = row.RentalAddress
319331
};
320332

321333
error = await _geocoder.GetAddressAsync(newAddress);
@@ -350,9 +362,12 @@ private async Task<DssRentalListing> CreateOrUpdateRentalListing(DssRentalListin
350362

351363
listing.IsChangedOriginalAddress = true;
352364

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+
}
356371

357372
_addressRepo.ReplaceAddress(listing, newAddress);
358373

@@ -363,12 +378,16 @@ private async Task<DssRentalListing> CreateOrUpdateRentalListing(DssRentalListin
363378
{
364379
var newAddress = new DssPhysicalAddress
365380
{
366-
OriginalAddressTxt = row.RentalAddress,
367-
RegRentalUnitNo = row.RentalUnit,
368-
RegRentalStreetNo = row.RentalStreet,
369-
RegRentalPostalCode = row.RentalPostal,
381+
OriginalAddressTxt = row.RentalAddress
370382
};
371383

384+
if (isRegistrationValid)
385+
{
386+
newAddress.RegRentalUnitNo = row.RentalUnit;
387+
newAddress.RegRentalStreetNo = row.RentalStreet;
388+
newAddress.RegRentalPostalCode = row.RentalPostal;
389+
}
390+
372391
error = await _geocoder.GetAddressAsync(newAddress);
373392

374393
if (error.IsEmpty() && newAddress.LocationGeometry is not null && newAddress.LocationGeometry is Point point)

0 commit comments

Comments
 (0)