コード例 #1
0
        private static void PopulateViewModelBasedOnOrganisation(AddOrganisationFoundViewModel viewModel, Organisation organisation)
        {
            // Name
            viewModel.Name = organisation.OrganisationName;

            // Address
            OrganisationAddress organisationAddress = organisation.GetLatestAddress();
            string addressString = organisationAddress?.GetAddressString() ?? "";

            viewModel.AddressLines = addressString.Split(",").ToList();

            // IsUkAddress
            bool?isUkAddress = organisationAddress?.IsUkAddress;

            if (isUkAddress.HasValue)
            {
                viewModel.IsUkAddress = isUkAddress.Value
                    ? AddOrganisationIsUkAddress.Yes
                    : AddOrganisationIsUkAddress.No;
            }
            else
            {
                viewModel.IsUkAddress = PostcodesIoApi.IsValidPostcode(organisationAddress?.GetPostCodeInAllCaps())
                    ? AddOrganisationIsUkAddress.Yes
                    : (AddOrganisationIsUkAddress?)null;
            }

            // Company number
            if (!string.IsNullOrWhiteSpace(organisation.CompanyNumber))
            {
                viewModel.CompanyNumber = organisation.CompanyNumber;
            }
        }
        public void PopulateFromOrganisationAddress(OrganisationAddress address)
        {
            PoBox    = address?.PoBox;
            Address1 = address?.Address1;
            Address2 = address?.Address2;
            Address3 = address?.Address3;
            TownCity = address?.TownCity;
            County   = address?.County;
            Country  = address?.Country;
            PostCode = address?.GetPostCodeInAllCaps();

            if (address?.IsUkAddress != null)
            {
                IsUkAddress = address.IsUkAddress.Value
                    ? ManuallyChangeOrganisationAddressIsUkAddress.Yes
                    : ManuallyChangeOrganisationAddressIsUkAddress.No;
            }
        }
コード例 #3
0
        private static bool IsNewOrganisationAddressNullOrEmpty(OrganisationAddress address)
        {
            // Some organisations are not required to provide information to Companies House, and so we might get an empty
            // address. See https://wck2.companieshouse.gov.uk/goWCK/help/en/stdwc/excl_ch.html for more details. In other cases
            // organisations may have deleted their information when closing an organisation or merging with another.
            if (
                string.IsNullOrEmpty(address.Address1) &&
                string.IsNullOrEmpty(address.Address2) &&
                string.IsNullOrEmpty(address.Address3) &&
                string.IsNullOrEmpty(address.TownCity) &&
                string.IsNullOrEmpty(address.County) &&
                string.IsNullOrEmpty(address.Country) &&
                string.IsNullOrEmpty(address.PoBox) &&
                string.IsNullOrEmpty(address.GetPostCodeInAllCaps())
                )
            {
                return(true);
            }

            return(false);
        }
コード例 #4
0
        public FileContentResult DownloadOrganisationAddresses()
        {
            List <Organisation> organisationAddresses = dataRepository.GetAll <Organisation>()
                                                        .Where(org => org.Status == OrganisationStatuses.Active)
                                                        .Include(org => org.OrganisationAddresses)
                                                        // This .ToList() materialises the collection (i.e. runs the SQL query)
                                                        .ToList()
                                                        // We only want organisations with valid addresses
                                                        // The following filter only works in code (cannot be converted to SQL) so must be done after the first .ToList()
                                                        .Where(org => org.GetLatestAddress() != null)
                                                        .ToList();

            var records = organisationAddresses.Select(
                org =>
            {
                OrganisationAddress address = org.GetLatestAddress();
                string postCode             = address.GetPostCodeInAllCaps();
                return(new
                {
                    org.OrganisationId,
                    org.OrganisationName,
                    address.PoBox,
                    address.Address1,
                    address.Address2,
                    address.Address3,
                    address.TownCity,
                    address.County,
                    address.Country,
                    postCode,
                });
            })
                          .ToList();

            string            fileDownloadName  = $"Gpg-OrganisationAddresses-{new GDSDateFormatter(VirtualDateTime.Now).FullStartDateTime}.csv";
            FileContentResult fileContentResult = DownloadHelper.CreateCsvDownload(records, fileDownloadName);

            return(fileContentResult);
        }