} // 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