} // IsOwner private LandRegistryDataModel GetLandRegistryData(out LandRegistryDB landRegistry) { Log.Debug("GetLandRegistryData begin cId {0} titleNumber {1}", this.customerID, this.titleNumber); //check cash var landRegistryLoad = new LandRegistryLoad(this.customerID); landRegistryLoad.Execute(); var customersLrs = landRegistryLoad.Result; var cache = customersLrs.Where(x => x.TitleNumber == this.titleNumber && ((x.RequestTypeEnum == LandRegistryRequestType.Res) || (x.RequestTypeEnum == LandRegistryRequestType.ResPoll)) && x.ResponseTypeEnum == LandRegistryResponseType.Success) .OrderByDescending(x => x.InsertDate) .FirstOrDefault(); if (cache != null) { var b = new LandRegistryModelBuilder(); var cacheModel = new LandRegistryDataModel { Request = cache.Request, Response = cache.Response, Res = b.BuildResModel(cache.Response), RequestType = cache.RequestTypeEnum, ResponseType = cache.ResponseTypeEnum, DataSource = LandRegistryDataSource.Cache }; if (!cache.Owners.Any()) { var owners = new List <LandRegistryOwnerDB>(); foreach (var owner in cacheModel.Res.Proprietorship.ProprietorshipParties) { var ownerDB = new LandRegistryOwnerDB { LandRegistryId = cache.Id, FirstName = owner.PrivateIndividualForename, LastName = owner.PrivateIndividualSurname, CompanyName = owner.CompanyName, CompanyRegistrationNumber = owner.CompanyRegistrationNumber, }; owners.Add(ownerDB); DB.ExecuteNonQuery("LandRegistryOwnerDBSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", ownerDB)); } cache.Owners = owners; } landRegistry = cache; return(cacheModel); } var isProd = CurrentValues.Instance.LandRegistryProd; ILandRegistryApi lr; if (isProd) { lr = new LandRegistryApi( CurrentValues.Instance.LandRegistryUserName, Encrypted.Decrypt(CurrentValues.Instance.LandRegistryPassword), CurrentValues.Instance.LandRegistryFilePath); } else { lr = new LandRegistryTestApi(); } LandRegistryDataModel model; if (this.titleNumber != null) { model = lr.Res(this.titleNumber, this.customerID); var customer = ObjectFactory.GetInstance <CustomerRepository>().Get(this.customerID); var lrDB = new LandRegistryDB { CustomerId = this.customerID, InsertDate = DateTime.UtcNow, TitleNumber = this.titleNumber, Request = model.Request, Response = model.Response, RequestType = model.RequestType.ToString(), ResponseType = model.ResponseType.ToString(), AttachmentPath = model.Attachment != null ? model.Attachment.FilePath : null }; int lrID = DB.ExecuteScalar <int>("LandRegistryDBSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", lrDB)); var owners = new List <LandRegistryOwnerDB>(); if (model.ResponseType == LandRegistryResponseType.Success && model.Res != null && model.Res.Proprietorship != null && model.Res.Proprietorship.ProprietorshipParties != null) { foreach (var owner in model.Res.Proprietorship.ProprietorshipParties) { var ownerDB = new LandRegistryOwnerDB { LandRegistryId = lrID, FirstName = owner.PrivateIndividualForename, LastName = owner.PrivateIndividualSurname, CompanyName = owner.CompanyName, CompanyRegistrationNumber = owner.CompanyRegistrationNumber, }; owners.Add(ownerDB); DB.ExecuteNonQuery("LandRegistryOwnerDBSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", ownerDB)); } lrDB.Owners = owners; } landRegistry = lrDB; if (model.Attachment != null) { var fileRepo = ObjectFactory.GetInstance <NHibernateRepositoryBase <MP_AlertDocument> >(); var doc = new MP_AlertDocument { BinaryBody = model.Attachment.AttachmentContent, Customer = customer, Description = "LandRegistry", UploadDate = DateTime.UtcNow, DocName = model.Attachment.FileName }; fileRepo.SaveOrUpdate(doc); model.Attachment.AttachmentContent = null; } } else { landRegistry = null; model = new LandRegistryDataModel { Res = new LandRegistryResModel { Rejection = new LandRegistryRejectionModel { Reason = "Please perform enquiry first to retrieve title number" } }, ResponseType = LandRegistryResponseType.None }; } model.DataSource = LandRegistryDataSource.Api; return(model); } // GetLandRegistryData
} // Execute private LandRegistryDataModel GetLandRegistryEnquiryData() { try { //check cache var landRegistryLoad = new LandRegistryLoad(this.customerID); landRegistryLoad.Execute(); var customersLrs = landRegistryLoad.Result; var cache = customersLrs.Where(x => x.RequestTypeEnum == LandRegistryRequestType.Enquiry).ToList(); if (cache.Any()) { foreach (var landRegistry in cache) { var lrReq = Serialized.Deserialize <LandRegistryLib.LREnquiryServiceNS.RequestSearchByPropertyDescriptionV2_0Type>(landRegistry.Request); Q1AddressType lrAddress = lrReq.Product.SubjectProperty.Address; if (lrAddress.IsA(this.buildingNumber, this.buildingName, this.streetName, this.cityName, this.postCode)) { var b = new LandRegistryModelBuilder(); var cacheModel = new LandRegistryDataModel { Request = landRegistry.Request, Response = landRegistry.Response, Enquery = b.BuildEnquiryModel(landRegistry.Response), RequestType = landRegistry.RequestTypeEnum, ResponseType = landRegistry.ResponseTypeEnum, DataSource = LandRegistryDataSource.Cache, }; return(cacheModel); } // if } // for each } // if } catch (Exception ex) { Log.Warn(ex, "Failed to retrieve land registry enquiry from cache."); } // try bool isProd = CurrentValues.Instance.LandRegistryProd; ILandRegistryApi lr; if (isProd) { lr = new LandRegistryApi( CurrentValues.Instance.LandRegistryUserName, Encrypted.Decrypt(CurrentValues.Instance.LandRegistryPassword), CurrentValues.Instance.LandRegistryFilePath); } else { lr = new LandRegistryTestApi(); } var model = lr.EnquiryByPropertyDescription(this.buildingNumber, this.buildingName, this.streetName, this.cityName, this.postCode, this.customerID); var lrDB = new LandRegistryDB { CustomerId = this.customerID, InsertDate = DateTime.UtcNow, Postcode = string.IsNullOrEmpty(this.postCode) ? string.Format("{3}{0},{1},{2}", this.buildingNumber, this.streetName, this.cityName, this.buildingName) : this.postCode, Request = model.Request, Response = model.Response, RequestType = model.RequestType.ToString(), ResponseType = model.ResponseType.ToString() }; int lrID = DB.ExecuteScalar <int>("LandRegistryDBSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", lrDB)); Log.Info("LandRegistryDBSave {0}", lrID); model.DataSource = LandRegistryDataSource.Api; return(model); } // GetLandRegistryEnquiryData
} // ExecuteStep private void QueryLandRegistry() { var customerAddressesHelper = new CustomerAddressHelper(this.customerID); customerAddressesHelper.Execute(); foreach (CustomerAddressModel address in customerAddressesHelper.OwnedAddresses) { LandRegistryDataModel model = null; if (!string.IsNullOrEmpty(address.HouseName)) { model = LandRegistryEnquiry.Get( this.customerID, null, address.HouseName, null, null, address.PostCode ); } else if (!string.IsNullOrEmpty(address.HouseNumber)) { model = LandRegistryEnquiry.Get( this.customerID, address.HouseNumber, null, null, null, address.PostCode ); } else if ( !string.IsNullOrEmpty(address.FlatOrApartmentNumber) && string.IsNullOrEmpty(address.HouseNumber) ) { model = LandRegistryEnquiry.Get( this.customerID, address.FlatOrApartmentNumber, null, null, null, address.PostCode ); } // if bool doLandRegistry = (model != null) && (model.Enquery != null) && (model.ResponseType == LandRegistryResponseType.Success) && (model.Enquery.Titles != null) && (model.Enquery.Titles.Count == 1); if (doLandRegistry) { var lrr = new LandRegistryRes(this.customerID, model.Enquery.Titles[0].TitleNumber); lrr.PartialExecute(); LandRegistryDB dbLandRegistry = lrr.LandRegistry; LandRegistryDataModel landRegistryDataModel = lrr.RawResult; if (landRegistryDataModel.ResponseType == LandRegistryResponseType.Success) { bool isOwnerAccordingToLandRegistry = LandRegistryRes.IsOwner( this.customerID, this.customerFullName, landRegistryDataModel.Response, landRegistryDataModel.Res.TitleNumber ); DB.ExecuteNonQuery( "AttachCustomerAddrToLandRegistryAddr", CommandSpecies.StoredProcedure, new QueryParameter("@LandRegistryAddressID", dbLandRegistry.Id), new QueryParameter("@CustomerAddressID", address.AddressId), new QueryParameter("@IsOwnerAccordingToLandRegistry", isOwnerAccordingToLandRegistry) ); } // if } else { int num = 0; if (model != null && model.Enquery != null && model.Enquery.Titles != null) { num = model.Enquery.Titles.Count; } Log.Warn( "No land registry retrieved for customer id: {5}," + "house name: {0}, house number: {1}, flat number: {2}, postcode: {3}, # of inquiries {4}", address.HouseName, address.HouseNumber, address.FlatOrApartmentNumber, address.PostCode, num, this.customerID ); } // if } // for each } // QueryLandRegistry
public override void Execute() { RawResult = GetLandRegistryEnquiryData(); Result = new Serialized(RawResult); } // Execute