Beispiel #1
0
        public WorkAddress GetWorkAddressIDM(IDMOrganisation org)
        {
            var launderer = new CachedAddressLaunderer(_cachedRepo, _actualLaunderer, _coordinates);

            if (org.Vejnavn == null || org.Vejnavn == "")
            {
                return(null);
            }

            var splitStreetAddress = SplitAddressIDM(org.Vejnavn, org.PostNr, org.PostDistrikt);

            var addressToLaunder = new Address
            {
                StreetName   = splitStreetAddress.ElementAt(0),
                StreetNumber = splitStreetAddress.ElementAt(1),
                ZipCode      = Convert.ToInt32(splitStreetAddress.ElementAt(3)),
                Town         = splitStreetAddress.ElementAt(2),
                Description  = org.Navn
            };

            addressToLaunder = launderer.Launder(addressToLaunder);

            var launderedAddress = new WorkAddress()
            {
                StreetName   = addressToLaunder.StreetName,
                StreetNumber = addressToLaunder.StreetNumber,
                ZipCode      = addressToLaunder.ZipCode,
                Town         = addressToLaunder.Town,
                Latitude     = addressToLaunder.Latitude ?? "",
                Longitude    = addressToLaunder.Longitude ?? "",
                Description  = org.Navn
            };

            var existingOrg = _orgRepo.AsQueryable().FirstOrDefault(x => x.OrgOUID.Equals(org.OUID));

            // If the address hasn't changed then set the Id to be the same as the existing one.
            // That way a new address won't be created in the database.
            // If the address is not the same as the existing one,
            // Then the Id will be 0, and a new address will be created in the database.
            if (existingOrg != null &&
                existingOrg.Address != null &&
                existingOrg.Address.StreetName == launderedAddress.StreetName &&
                existingOrg.Address.StreetNumber == launderedAddress.StreetNumber &&
                existingOrg.Address.ZipCode == launderedAddress.ZipCode &&
                existingOrg.Address.Town == launderedAddress.Town &&
                existingOrg.Address.Latitude == launderedAddress.Latitude &&
                existingOrg.Address.Longitude == launderedAddress.Longitude &&
                existingOrg.Address.Description == launderedAddress.Description)
            {
                launderedAddress.Id = (int)existingOrg.AddressId;
            }
            else
            {
                var a = 2;
            }

            return(launderedAddress);
        }
Beispiel #2
0
        public IQueryable <IDMOrganisation> GetOrganisationsAsQueryableIDM()
        {
            string organisationView = _customSettings.DbViewOrganisation;

            if (organisationView == null)
            {
                _logger.Error($"{this.GetType().Name}, GetOrganisationsAsQueryable(): DATABASE_VIEW_ORGANISATION is null");
            }

            var result = new List <IDMOrganisation>();

            using (var sqlConnection1 = new MySqlConnection(_connectionString))
            {
                var cmd = new MySqlCommand()
                {
                    CommandText = $"SELECT * FROM {organisationView}",
                    CommandType = CommandType.Text,
                    Connection  = sqlConnection1
                };
                try
                {
                    sqlConnection1.Open();
                    var reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        var currentRow = new IDMOrganisation()
                        {
                            OUID             = SafeGetString(reader, 0),
                            Navn             = SafeGetString(reader, 1),
                            OverliggendeOUID = SafeGetString(reader, 2),
                            OverliggendeOrg  = SafeGetString(reader, 3),
                            Leder            = SafeGetString(reader, 4),
                            Vejnavn          = SafeGetString(reader, 5),
                            PostNr           = SafeGetString(reader, 6),
                            PostDistrikt     = SafeGetString(reader, 7)
                        };
                        result.Add(currentRow);
                    }
                }
                catch (EndOfStreamException eose)
                {
                    _logger.Error($"{this.GetType().Name}, GetOrganisationsAsQueryableIDM(): Connection timed out", eose);
                    throw;
                }
                catch (Exception e)
                {
                    _logger.Error($"{this.GetType().Name}, GetOrganisationsAsQueryableIDM(): Error when reading organisations from IDM view", e);
                    throw;
                }
            }
            return(result.AsQueryable());
        }