1
1
using AutoMapper ;
2
2
using Microsoft . EntityFrameworkCore ;
3
3
using Microsoft . Extensions . Logging ;
4
+ using Npgsql ;
4
5
using StrDss . Common ;
5
6
using StrDss . Data . Entities ;
6
7
using StrDss . Model ;
@@ -10,6 +11,9 @@ namespace StrDss.Data.Repositories
10
11
public interface IBizLicenseRepository
11
12
{
12
13
Task < BizLicenseDto ? > GetBizLicense ( long businessLicenceId ) ;
14
+ Task CreateBizLicTempTable ( ) ;
15
+ Task InsertRowToBizLicTempTable ( BizLicenseRowUntyped row , long providingOrganizationId ) ;
16
+ Task ProcessBizLicTempTable ( ) ;
13
17
}
14
18
15
19
public class BizLicenseRepository : RepositoryBase < DssBusinessLicence > , IBizLicenseRepository
@@ -23,5 +27,109 @@ public BizLicenseRepository(DssDbContext dbContext, IMapper mapper, ICurrentUser
23
27
{
24
28
return _mapper . Map < BizLicenseDto > ( await _dbSet . AsNoTracking ( ) . FirstOrDefaultAsync ( x => x . BusinessLicenceId == businessLicenceId ) ) ;
25
29
}
30
+
31
+ public async Task CreateBizLicTempTable ( )
32
+ {
33
+ await _dbContext . Database . ExecuteSqlRawAsync ( @"
34
+ CREATE TEMP TABLE biz_lic_table (
35
+ business_licence_no varchar(50) NOT NULL,
36
+ expiry_dt date NOT NULL,
37
+ physical_rental_address_txt varchar(250) NULL,
38
+ licence_type_txt varchar(320) NULL,
39
+ restriction_txt varchar(320) NULL,
40
+ business_nm varchar(320) NULL,
41
+ mailing_street_address_txt varchar(100) NULL,
42
+ mailing_city_nm varchar(100) NULL,
43
+ mailing_province_cd varchar(2) NULL,
44
+ mailing_postal_cd varchar(10) NULL,
45
+ business_owner_nm varchar(320) NULL,
46
+ business_owner_phone_no varchar(30) NULL,
47
+ business_owner_email_address_dsc varchar(320) NULL,
48
+ business_operator_nm varchar(320) NULL,
49
+ business_operator_phone_no varchar(30) NULL,
50
+ business_operator_email_address_dsc varchar(320) NULL,
51
+ infraction_txt varchar(320) NULL,
52
+ infraction_dt date NULL,
53
+ property_zone_txt varchar(100) NULL,
54
+ available_bedrooms_qty int2 NULL,
55
+ max_guests_allowed_qty int2 NULL,
56
+ is_principal_residence bool NULL,
57
+ is_owner_living_onsite bool NULL,
58
+ is_owner_property_tenant bool NULL,
59
+ property_folio_no varchar(30) NULL,
60
+ property_parcel_identifier_no varchar(30) NULL,
61
+ property_legal_description_txt varchar(320) NULL,
62
+ licence_status_type varchar(25) NOT NULL,
63
+ providing_organization_id int8 NOT NULL
64
+ );
65
+ " ) ;
66
+ }
67
+
68
+ public async Task InsertRowToBizLicTempTable ( BizLicenseRowUntyped row , long providingOrganizationId )
69
+ {
70
+ var insertSql = @"
71
+ INSERT INTO biz_lic_table (
72
+ business_licence_no, expiry_dt, physical_rental_address_txt, licence_type_txt, restriction_txt, business_nm, mailing_street_address_txt,
73
+ mailing_city_nm, mailing_province_cd, mailing_postal_cd, business_owner_nm, business_owner_phone_no, business_owner_email_address_dsc,
74
+ business_operator_nm, business_operator_phone_no, business_operator_email_address_dsc, infraction_txt, infraction_dt,
75
+ property_zone_txt, available_bedrooms_qty, max_guests_allowed_qty, is_principal_residence, is_owner_living_onsite,
76
+ is_owner_property_tenant, property_folio_no, property_parcel_identifier_no, property_legal_description_txt,
77
+ licence_status_type, providing_organization_id
78
+ )
79
+ VALUES (
80
+ @BusinessLicenceNo, @ExpiryDt, @PhysicalRentalAddressTxt, @LicenceTypeTxt, @RestrictionTxt, @BusinessNm, @MailingStreetAddressTxt,
81
+ @MailingCityNm, @MailingProvinceCd, @MailingPostalCd, @BusinessOwnerNm, @BusinessOwnerPhoneNo, @BusinessOwnerEmailAddressDsc,
82
+ @BusinessOperatorNm, @BusinessOperatorPhoneNo, @BusinessOperatorEmailAddressDsc, @InfractionTxt, @InfractionDt,
83
+ @PropertyZoneTxt, @AvailableBedroomsQty, @MaxGuestsAllowedQty, @IsPrincipalResidence, @IsOwnerLivingOnsite,
84
+ @IsOwnerPropertyTenant, @PropertyFolioNo, @PropertyParcelIdentifierNo, @PropertyLegalDescriptionTxt,
85
+ @LicenceStatusType, @ProvidingOrganizationId
86
+ );" ;
87
+
88
+ bool ConvertToBool ( string value ) => value ? . ToUpper ( ) == "Y" ;
89
+
90
+ DateTime ? ConvertToDate ( string value ) => DateTime . TryParseExact ( value , "yyyy-MM-dd" , null , System . Globalization . DateTimeStyles . None , out var date ) ? date : ( DateTime ? ) null ;
91
+
92
+ short ? ConvertToInt2 ( string value ) => short . TryParse ( value , out var result ) ? result : ( short ? ) null ;
93
+
94
+ var parameters = new List < NpgsqlParameter >
95
+ {
96
+ new NpgsqlParameter ( "@businessLicenceNo" , row . BusinessLicenceNo ) ,
97
+ new NpgsqlParameter ( "@expiryDt" , ConvertToDate ( row . ExpiryDt ) ) ,
98
+ new NpgsqlParameter ( "@physicalRentalAddressTxt" , row . PhysicalRentalAddressTxt ?? ( object ) DBNull . Value ) ,
99
+ new NpgsqlParameter ( "@licenceTypeTxt" , row . LicenceTypeTxt ?? ( object ) DBNull . Value ) ,
100
+ new NpgsqlParameter ( "@restrictionTxt" , row . RestrictionTxt ?? ( object ) DBNull . Value ) ,
101
+ new NpgsqlParameter ( "@businessNm" , row . BusinessNm ?? ( object ) DBNull . Value ) ,
102
+ new NpgsqlParameter ( "@mailingStreetAddressTxt" , row . MailingStreetAddressTxt ?? ( object ) DBNull . Value ) ,
103
+ new NpgsqlParameter ( "@mailingCityNm" , row . MailingCityNm ?? ( object ) DBNull . Value ) ,
104
+ new NpgsqlParameter ( "@mailingProvinceCd" , row . MailingProvinceCd ?? ( object ) DBNull . Value ) ,
105
+ new NpgsqlParameter ( "@mailingPostalCd" , row . MailingPostalCd ?? ( object ) DBNull . Value ) ,
106
+ new NpgsqlParameter ( "@businessOwnerNm" , row . BusinessOwnerNm ?? ( object ) DBNull . Value ) ,
107
+ new NpgsqlParameter ( "@businessOwnerPhoneNo" , row . BusinessOwnerPhoneNo ?? ( object ) DBNull . Value ) ,
108
+ new NpgsqlParameter ( "@businessOwnerEmailAddressDsc" , row . BusinessOwnerEmailAddressDsc ?? ( object ) DBNull . Value ) ,
109
+ new NpgsqlParameter ( "@businessOperatorNm" , row . BusinessOperatorNm ?? ( object ) DBNull . Value ) ,
110
+ new NpgsqlParameter ( "@businessOperatorPhoneNo" , row . BusinessOperatorPhoneNo ?? ( object ) DBNull . Value ) ,
111
+ new NpgsqlParameter ( "@businessOperatorEmailAddressDsc" , row . BusinessOperatorEmailAddressDsc ?? ( object ) DBNull . Value ) ,
112
+ new NpgsqlParameter ( "@infractionTxt" , row . InfractionTxt ?? ( object ) DBNull . Value ) ,
113
+ new NpgsqlParameter ( "@infractionDt" , ConvertToDate ( row . InfractionDt ) ?? ( object ) DBNull . Value ) ,
114
+ new NpgsqlParameter ( "@propertyZoneTxt" , row . PropertyZoneTxt ?? ( object ) DBNull . Value ) ,
115
+ new NpgsqlParameter ( "@availableBedroomsQty" , ConvertToInt2 ( row . AvailableBedroomsQty ) ?? ( object ) DBNull . Value ) ,
116
+ new NpgsqlParameter ( "@maxGuestsAllowedQty" , ConvertToInt2 ( row . MaxGuestsAllowedQty ) ?? ( object ) DBNull . Value ) ,
117
+ new NpgsqlParameter ( "@isPrincipalResidence" , ConvertToBool ( row . IsPrincipalResidence ) ) ,
118
+ new NpgsqlParameter ( "@isOwnerLivingOnsite" , ConvertToBool ( row . IsOwnerLivingOnsite ) ) ,
119
+ new NpgsqlParameter ( "@isOwnerPropertyTenant" , ConvertToBool ( row . IsOwnerPropertyTenant ) ) ,
120
+ new NpgsqlParameter ( "@propertyFolioNo" , row . PropertyFolioNo ?? ( object ) DBNull . Value ) ,
121
+ new NpgsqlParameter ( "@propertyParcelIdentifierNo" , row . PropertyParcelIdentifierNo ?? ( object ) DBNull . Value ) ,
122
+ new NpgsqlParameter ( "@propertyLegalDescriptionTxt" , row . PropertyLegalDescriptionTxt ?? ( object ) DBNull . Value ) ,
123
+ new NpgsqlParameter ( "@licenceStatusType" , row . LicenceStatusType ) ,
124
+ new NpgsqlParameter ( "@providingOrganizationId" , providingOrganizationId )
125
+ } ;
126
+
127
+ await _dbContext . Database . ExecuteSqlRawAsync ( insertSql , parameters . ToArray ( ) ) ;
128
+ }
129
+
130
+ public async Task ProcessBizLicTempTable ( )
131
+ {
132
+ await _dbContext . Database . ExecuteSqlRawAsync ( "CALL dss_process_biz_lic_table();" ) ;
133
+ }
26
134
}
27
135
}
0 commit comments