} // Execute public void LinkLandRegistryAndAddress(int customerId, string response, int landRegistryId) { var customers = ObjectFactory.GetInstance <CustomerRepository>(); var customerAddressRepository = ObjectFactory.GetInstance <CustomerAddressRepository>(); var customer = customers.Get(customerId); var bb = new LandRegistryModelBuilder(); LandRegistryResModel landRegistryResModel = bb.BuildResModel(response); bool isOwnerAccordingToLandRegistry = IsOwner(customer, response, this.titleNumber); if (isOwnerAccordingToLandRegistry) { var ownedProperties = new List <CustomerAddress>(customer.AddressInfo.OtherPropertiesAddresses); if (customer.PropertyStatus.IsOwnerOfMainAddress) { if (customer.AddressInfo.PersonalAddress.Count == 1) { ownedProperties.Add(customer.AddressInfo.PersonalAddress.First()); } } // if foreach (CustomerAddress ownedProperty in ownedProperties) { bool foundMatching = false; foreach (LandRegistryAddressModel propertyAddress in landRegistryResModel.PropertyAddresses) { if (propertyAddress.PostCode == ownedProperty.Postcode) { foundMatching = true; break; } } if (foundMatching) { ownedProperty.IsOwnerAccordingToLandRegistry = true; customerAddressRepository.SaveOrUpdate(ownedProperty); DB.ExecuteNonQuery(string.Format("UPDATE LandRegistry SET AddressId = {0} WHERE Id = {1}", ownedProperty.AddressId, landRegistryId), CommandSpecies.Text); break; } } // for each } // if } // LinkLandRegistryAndAddress
public PropertiesModel Create(Customer customer) { int experianMortgage; int experianMortgageCount; var data = new PropertiesModel(); var customersLrs = this.serviceClient.Instance.LandRegistryLoad(customer.Id, this.context.UserId).Value; if (customer.PropertyStatus != null && customer.PropertyStatus.IsOwnerOfMainAddress) { var currentAddresses = customer.AddressInfo.PersonalAddress.Where(x => x.AddressType == CustomerAddressType.PersonalAddress); foreach (var customerAddress in currentAddresses) { var property = GetPropertyModel(customer, customerAddress, customersLrs); if (property != null) { data.Properties.Add(property); } } } foreach (CustomerAddress ownedProperty in customer.AddressInfo.OtherPropertiesAddresses) { var property = GetPropertyModel(customer, ownedProperty, customersLrs); if (property != null) { data.Properties.Add(property); } } var unmappedLrs = customersLrs.Where(x => x.RequestType == LandRegistryRequestType.Res.ToString() && !x.AddressID.HasValue); foreach (var unmappedLr in unmappedLrs) { LandRegistryResModel lrModel = this.landRegistryModelBuilder.BuildResModel(unmappedLr.Response, unmappedLr.TitleNumber); lrModel.AttachmentId = this.fileRepo.GetAll() .Where( x => x.Customer == customer && x.Description == "LandRegistry" && x.DocName.StartsWith(lrModel.TitleNumber)) .Select(x => x.Id) .FirstOrDefault(); var unMappedProperty = new PropertyModel { AddressType = "Unmapped LR", VerifyStatus = PropertyVerifyStatus.NotVerified, LandRegistries = new List <LandRegistryResModel> { lrModel } }; if (lrModel.PropertyAddresses != null && lrModel.PropertyAddresses.Any()) { unMappedProperty.Postcode = lrModel.PropertyAddresses.First().PostCode; unMappedProperty.NumberOfOwners = unmappedLr.Owners.Count(); unMappedProperty.FormattedAddress = lrModel.PropertyAddresses.First().Lines; } data.Properties.Add(unMappedProperty); } CrossCheckModel.GetMortgagesData(this.context.UserId, customer, out experianMortgage, out experianMortgageCount); data.Init( numberOfProperties: data.Properties .Count(x => x.VerifyStatus == PropertyVerifyStatus.VerifiedOwned), numberOfMortgages: experianMortgageCount, assetsValue: data.Properties .Where(x => x.VerifyStatus == PropertyVerifyStatus.VerifiedOwned) .Sum(x => x.MarketValue), totalMortgages: experianMortgage, zooplaAverage: data.Properties .Where(x => x.Zoopla != null && x.VerifyStatus == PropertyVerifyStatus.VerifiedOwned) .Sum(x => x.Zoopla.AverageSoldPrice1Year) ); return(data); }