Exemple #1
0
        /// <summary>
        /// Add new address location to database.
        /// </summary>
        /// <param name="addressLocationDTO">AddressLocationDTO object</param>
        /// <returns>Task<int></returns>
        public async Task <int> SaveNewAddressLocation(AddressLocationDTO addressLocationDTO)
        {
            try
            {
                using (loggingHelper.RMTraceManager.StartTrace("DataService.SaveNewAddressLocation"))
                {
                    string method = MethodHelper.GetActualAsyncMethodName();
                    loggingHelper.Log(method + LoggerTraceConstants.COLON + LoggerTraceConstants.MethodExecutionStarted, TraceEventType.Verbose, null, LoggerTraceConstants.Category, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodEntryEventId, LoggerTraceConstants.Title);

                    var addressLocationEntity = new AddressLocation();

                    GenericMapper.Map(addressLocationDTO, addressLocationEntity);
                    DataContext.AddressLocations.Add(addressLocationEntity);
                    var saveNewAddressLocation = await DataContext.SaveChangesAsync();

                    loggingHelper.Log(method + LoggerTraceConstants.COLON + LoggerTraceConstants.MethodExecutionCompleted, TraceEventType.Verbose, null, LoggerTraceConstants.Category, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodExitEventId, LoggerTraceConstants.Title);
                    return(saveNewAddressLocation);
                }
            }
            catch (DbUpdateException dbUpdateException)
            {
                throw new DataAccessException(dbUpdateException, string.Format(ErrorConstants.Err_SqlAddException, string.Concat("Address Location for UDPRN:", addressLocationDTO.UDPRN)));
            }
            catch (NotSupportedException notSupportedException)
            {
                notSupportedException.Data.Add(ErrorConstants.UserFriendlyErrorMessage, ErrorConstants.Err_Default);
                throw new InfrastructureException(notSupportedException, ErrorConstants.Err_NotSupportedException);
            }
            catch (ObjectDisposedException disposedException)
            {
                disposedException.Data.Add(ErrorConstants.UserFriendlyErrorMessage, ErrorConstants.Err_Default);
                throw new ServiceException(disposedException, ErrorConstants.Err_ObjectDisposedException);
            }
        }
Exemple #2
0
        public async Task <IActionResult> GetAddressLocationByUDPRN(int udprn)
        {
            using (loggingHelper.RMTraceManager.StartTrace("WebService.GetAddressLocationByUDPRN"))
            {
                if (udprn == 0)
                {
                    throw new ArgumentException(nameof(udprn));
                }

                try
                {
                    string methodName = typeof(ThirdPartyAddressLocationController) + "." + nameof(GetAddressLocationByUDPRN);
                    loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationControllerMethodEntryEventId);
                    AddressLocationDTO addressLocationDTO = await this.thirdPartyAddressLocationBusinessService.GetAddressLocationByUDPRN(udprn);

                    loggingHelper.LogMethodExit(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationControllerMethodExitEventId);
                    return(Ok(addressLocationDTO));
                }
                catch (AggregateException ae)
                {
                    foreach (var exception in ae.InnerExceptions)
                    {
                        loggingHelper.Log(exception, TraceEventType.Error);
                    }

                    var realExceptions = ae.Flatten().InnerException;
                    throw realExceptions;
                }
            }
        }
Exemple #3
0
        public void SavePAFDetails_Check_MatchPostalAddressOnAddress_Insert()
        {
            PostalAddressDTO objPostalAddress = new PostalAddressDTO()
            {
                Time                = "7/19/2016",
                Date                = "8:37:00",
                AmendmentType       = "I",
                AmendmentDesc       = "new insert",
                Postcode            = "YO23 1DQ",
                PostTown            = "York",
                UDPRN               = 54162429,
                DeliveryPointSuffix = "1A",
                AddressType_GUID    = new Guid("A08C5212-6123-4EAF-9C27-D4A8035A8974")
            };
            List <PostalAddressDTO> lstPostalAddress = new List <PostalAddressDTO>();

            lstPostalAddress.Add(objPostalAddress);
            AddressLocationDTO objAddressLocation = new AddressLocationDTO()
            {
                UDPRN = 54162428
            };

            var result = testCandidate.ProcessPAFDetails(lstPostalAddress);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Result);
        }
Exemple #4
0
        /// <summary>
        /// This method is used to fetch data for Access Links.
        /// </summary>
        /// <param name="uDPRN">UDPRN</param>
        /// <returns>Address Location DTO</returns>
        public async Task <object> GetAddressLocationByUDPRNJson(int uDPRN)
        {
            using (loggingHelper.RMTraceManager.StartTrace("Business.GetAddressLocationByUDPRNJson"))
            {
                string methodName = typeof(ThirdPartyAddressLocationBusinessService) + "." + nameof(GetAddressLocationByUDPRNJson);
                loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodEntryEventId);

                AddressLocationDataDTO addressLocationDataDto = await this.addressLocationDataService.GetAddressLocationByUDPRN(uDPRN);

                Mapper.Initialize(cfg => cfg.CreateMap <AddressLocationDataDTO, AddressLocationDTO>());
                AddressLocationDTO addressLocationDto = Mapper.Map <AddressLocationDataDTO, AddressLocationDTO>(addressLocationDataDto);
                var getAddressLocationJsonData        = GetAddressLocationJsonData(addressLocationDto);
                loggingHelper.LogMethodExit(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodExitEventId);
                return(getAddressLocationJsonData);
            }
        }
Exemple #5
0
        /// <summary>
        /// Get AddressLocation by UDPRN
        /// </summary>
        /// <param name="udprn">UDPRN id</param>
        /// <returns>AddressLocationDTO object</returns>
        public async Task <AddressLocationDTO> GetAddressLocationByUDPRN(int uDPRN)
        {
            using (loggingHelper.RMTraceManager.StartTrace("Business.GetAddressLocationByUDPRN"))
            {
                string methodName = typeof(ThirdPartyAddressLocationBusinessService) + "." + nameof(GetAddressLocationByUDPRN);
                loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodEntryEventId);

                var addressLocationDataDto = await addressLocationDataService.GetAddressLocationByUDPRN(uDPRN);

                Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <AddressLocationDataDTO, AddressLocationDTO>().MaxDepth(1);
                });
                Mapper.Configuration.CreateMapper();

                AddressLocationDTO addressLocationDto = Mapper.Map <AddressLocationDataDTO, AddressLocationDTO>(addressLocationDataDto);

                loggingHelper.LogMethodExit(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodExitEventId);
                return(addressLocationDto);
            }
        }
Exemple #6
0
        /// <summary>
        /// This method is used to fetch GeoJson data for Address Location.
        /// </summary>
        /// <param name="addressLocationDto">Address Location DTO</param>
        /// <returns>lstDeliveryPointDTO</returns>
        private object GetAddressLocationJsonData(AddressLocationDTO addressLocationDto)
        {
            using (loggingHelper.RMTraceManager.StartTrace("Business.GetAddressLocationJsonData"))
            {
                string methodName = typeof(ThirdPartyAddressLocationBusinessService) + "." + nameof(GetAddressLocationJsonData);
                loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodEntryEventId);

                var addressLocationGeoJson = new GeoJson
                {
                    features = new List <Feature>()
                };

                if (addressLocationDto.LocationXY != null)
                {
                    SqlGeometry addressLocationSqlGeometry = SqlGeometry.STGeomFromWKB(new SqlBytes(addressLocationDto.LocationXY.AsBinary()), ThirdPartyAddressLocationConstants.BNGCOORDINATESYSTEM);

                    var feature = new Feature
                    {
                        id         = addressLocationDto.ID.ToString(),
                        properties = new Dictionary <string, JToken>
                        {
                            { ThirdPartyAddressLocationConstants.UDPRN, addressLocationDto.UDPRN },
                            { ThirdPartyAddressLocationConstants.Latitude, addressLocationDto.Lattitude },
                            { ThirdPartyAddressLocationConstants.Longitude, addressLocationDto.Longitude },
                        },
                        geometry = new Geometry
                        {
                            coordinates = new double[] { addressLocationSqlGeometry.STX.Value, addressLocationSqlGeometry.STY.Value }
                        }
                    };

                    addressLocationGeoJson.features.Add(feature);
                }

                loggingHelper.LogMethodExit(methodName, LoggerTraceConstants.ThirdPartyAddressLocationAPIPriority, LoggerTraceConstants.ThirdPartyAddressLocationDataServiceMethodExitEventId);
                return(addressLocationGeoJson);
            }
        }
Exemple #7
0
        protected override void OnSetup()
        {
            // OnSetup to be configured
            referenceDataCategoryDTOList = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO>()
            {
                new CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO()
                {
                    ReferenceDatas = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataDTO>()
                    {
                        new CommonLibrary.EntityFramework.DTO.ReferenceDataDTO()
                        {
                            ReferenceDataValue = FileType.Nyb.ToString(),
                            ID = Guid.NewGuid(),
                        }
                    },
                    CategoryName = PostalAddressType
                },

                new CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO()
                {
                    ReferenceDatas = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataDTO>()
                    {
                        new CommonLibrary.EntityFramework.DTO.ReferenceDataDTO()
                        {
                            ReferenceDataValue = FileType.Usr.ToString(),
                            ID = Guid.NewGuid(),
                        }
                    },
                    CategoryName = PostalAddressType
                },

                new CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO()
                {
                    ReferenceDatas = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataDTO>()
                    {
                        new CommonLibrary.EntityFramework.DTO.ReferenceDataDTO()
                        {
                            ReferenceDataValue = FileType.Paf.ToString(),
                            ID = new Guid("A08C5212-6123-4EAF-9C27-D4A8035A8974"),
                        }
                    },
                    CategoryName = PostalAddressType
                },

                new CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO()
                {
                    ReferenceDatas = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataDTO>()
                    {
                        new CommonLibrary.EntityFramework.DTO.ReferenceDataDTO()
                        {
                            ReferenceDataValue = PostCodeStatus.Live.GetDescription(),
                            ID = Guid.NewGuid(),
                        }
                    },
                    CategoryName = PostalAddressStatus
                },

                new CommonLibrary.EntityFramework.DTO.ReferenceDataCategoryDTO()
                {
                    ReferenceDatas = new List <CommonLibrary.EntityFramework.DTO.ReferenceDataDTO>()
                    {
                        new CommonLibrary.EntityFramework.DTO.ReferenceDataDTO()
                        {
                            ReferenceDataValue = PostCodeStatus.PendingDeleteInFMO.GetDescription(),
                            ID = Guid.NewGuid(),
                        }
                    },
                    CategoryName = PostalAddressStatus
                }
            };

            AddressLocationDTO addressLocationDTO = new AddressLocationDTO()
            {
                UDPRN      = 1234,
                LocationXY = DbGeometry.PointFromText("POINT(512722.70000000019 104752.6799999997)", 27700)
            };

            PostalAddressDataDTO postalAddressDataDTO = new PostalAddressDataDTO()
            {
                Postcode            = "YO23 1DQ",
                PostTown            = "York",
                UDPRN               = 54162429,
                DeliveryPointSuffix = "1A",
                AddressType_GUID    = new Guid("A08C5212-6123-4EAF-9C27-D4A8035A8974")
            };

            PostalAddressDTO postalAddressDTO = new PostalAddressDTO()
            {
                ID = Guid.Empty
            };

            mockPostalAddressDataService = CreateMock <IPostalAddressDataService>();
            // mockFileProcessingLogDataService = CreateMock<IFileProcessingLogDataService>();
            mockConfigurationHelper             = CreateMock <IConfigurationHelper>();
            mockLoggingHelper                   = CreateMock <ILoggingHelper>();
            mockHttpHandler                     = CreateMock <IHttpHandler>();
            mockPostalAddressIntegrationService = CreateMock <IPostalAddressIntegrationService>();

            var rmTraceManagerMock = new Mock <IRMTraceManager>();

            rmTraceManagerMock.Setup(x => x.StartTrace(It.IsAny <string>(), It.IsAny <Guid>()));
            mockLoggingHelper.Setup(x => x.RMTraceManager).Returns(rmTraceManagerMock.Object);
            mockPostalAddressIntegrationService.Setup(n => n.GetReferenceDataSimpleLists(It.IsAny <string>())).Returns(Task.FromResult(referenceDataCategoryDTOList[2]));
            mockPostalAddressIntegrationService.Setup(n => n.GetReferenceDataSimpleLists(It.IsAny <List <string> >())).Returns(Task.FromResult(referenceDataCategoryDTOList));
            mockPostalAddressIntegrationService.Setup(n => n.GetReferenceDataGuId(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(Guid.NewGuid()));
            mockPostalAddressIntegrationService.Setup(n => n.GetAddressLocationByUDPRN(It.IsAny <int>())).Returns(Task.FromResult(addressLocationDTO));
            mockPostalAddressDataService.Setup(n => n.DeleteNYBPostalAddress(It.IsAny <List <int> >(), It.IsAny <Guid>())).Returns(Task.FromResult(true));

            mockPostalAddressDataService.Setup(n => n.GetPostalAddresses(It.IsAny <List <Guid> >())).ReturnsAsync(new List <PostalAddressDataDTO>()
            {
                new PostalAddressDataDTO()
                {
                    Postcode = "1234"
                }
            });
            mockPostalAddressDataService.Setup(n => n.CheckForDuplicateNybRecords(It.IsAny <PostalAddressDataDTO>(), It.IsAny <Guid>())).Returns("PO1234");
            mockPostalAddressDataService.Setup(n => n.CheckForDuplicateAddressWithDeliveryPoints(It.IsAny <PostalAddressDataDTO>())).Returns(Task.FromResult(true));
            mockPostalAddressDataService.Setup(n => n.CreateAddressForDeliveryPoint(It.IsAny <PostalAddressDataDTO>())).Returns(addressTypeGUID);
            mockPostalAddressDataService.Setup(n => n.GetPostalAddress(It.IsAny <int>())).Returns(Task.FromResult(postalAddressDataDTO));
            mockPostalAddressDataService.Setup(n => n.GetPAFAddress(It.IsAny <int>(), It.IsAny <Guid>())).Returns(Task.FromResult(postalAddressDTO));

            // mockFileProcessingLogDataService.Setup(x => x.LogFileException(It.IsAny<FileProcessingLogDTO>()));

            testCandidate = new DataManagement.PostalAddress.WebAPI.BusinessService.Implementation.PostalAddressBusinessService(mockPostalAddressDataService.Object, mockLoggingHelper.Object, mockConfigurationHelper.Object, mockHttpHandler.Object, mockPostalAddressIntegrationService.Object);
        }