Example #1
0
        private StateOfExport GenerateStateOfExport(Draft.StateOfExport stateOfExport,
                                                    TransportRouteLookups lookups)
        {
            var returnValue = new StateOfExport();

            if (stateOfExport.CompetentAuthorityId.HasValue)
            {
                var competentAuthority = lookups.GetCompetentAuthority(stateOfExport.CompetentAuthorityId);

                returnValue.CompetentAuthorityName = competentAuthority.Name;
                returnValue.CompetentAuthorityCode = competentAuthority.Code;
            }

            if (stateOfExport.CountryId.HasValue)
            {
                returnValue.CountryName = lookups.GetCountry(stateOfExport.CountryId).Name;
            }

            if (stateOfExport.ExitPointId.HasValue)
            {
                returnValue.ExitPointName = lookups.GetEntryOrExitPoint(stateOfExport.ExitPointId).Name;
            }

            return(returnValue);
        }
Example #2
0
        private TransitState GenerateTransitState(Draft.TransitState transitState, TransportRouteLookups lookups)
        {
            var returnValue = new TransitState();

            if (transitState.CompetentAuthorityId.HasValue)
            {
                var competentAuthority = lookups.GetCompetentAuthority(transitState.CompetentAuthorityId);

                returnValue.CompetentAuthorityCode = competentAuthority.Code;
                returnValue.CompetentAuthorityName = competentAuthority.Name;
            }

            if (transitState.CountryId.HasValue)
            {
                returnValue.CountryName = lookups.GetCountry(transitState.CountryId).Name;
            }

            if (transitState.EntryPointId.HasValue)
            {
                returnValue.EntryPointName = lookups.GetEntryOrExitPoint(transitState.EntryPointId).Name;
            }

            if (transitState.ExitPointId.HasValue)
            {
                returnValue.ExitPointName = lookups.GetEntryOrExitPoint(transitState.ExitPointId).Name;
            }

            return(returnValue);
        }
Example #3
0
        public async Task <TransportRouteData> GetTransportRoute(Guid id,
                                                                 IList <Domain.Country> countries)
        {
            var idContainer = new TransportRouteIdContainer();

            var stateOfImport = await draftRepository.GetDraftData <Draft.StateOfImport>(id);

            var stateOfExport = await draftRepository.GetDraftData <Draft.StateOfExport>(id);

            var transitStateCollection = await draftRepository.GetDraftData <Draft.TransitStateCollection>(id);

            /*
             * We must find the ids for the competent authorities and entry or exit points used by
             * the state of export, import and transit states.
             * Since these are all nullable we use a series of methods to gather the non-null ids we need
             * to load data for. This is so we can load the data in 2 calls rather than multiple calls.
             */
            AddTransitStateIds(transitStateCollection, idContainer);
            AddStateOfExportIds(stateOfExport, idContainer);
            AddStateOfImportIds(stateOfImport, idContainer);

            var competentAuthorities = await competentAuthorityRepository.GetByIds(idContainer.CompetentAuthorityIds);

            var entryOrExitPoints = await entryOrExitPointRepository.GetByIds(idContainer.EntryOfExitPointIds);

            var lookups = new TransportRouteLookups(countries, competentAuthorities, entryOrExitPoints);

            // Use the loaded competent authorities and entry or exit points to retrieve names for summary data.
            return(new TransportRouteData(GenerateTransitStates(transitStateCollection, lookups),
                                          GenerateStateOfExport(stateOfExport, lookups),
                                          GenerateStateOfImport(stateOfImport, lookups),
                                          transitStateCollection.HasNoTransitStates));
        }
        public async Task<TransportRouteData> GetTransportRoute(Guid id,
            IList<Domain.Country> countries)
        {
            var idContainer = new TransportRouteIdContainer();

            var stateOfImport = await draftRepository.GetDraftData<Draft.StateOfImport>(id);
            var stateOfExport = await draftRepository.GetDraftData<Draft.StateOfExport>(id);
            var transitStateCollection = await draftRepository.GetDraftData<Draft.TransitStateCollection>(id);

            /* 
            * We must find the ids for the competent authorities and entry or exit points used by
            * the state of export, import and transit states.
            * Since these are all nullable we use a series of methods to gather the non-null ids we need
            * to load data for. This is so we can load the data in 2 calls rather than multiple calls.
            */
            AddTransitStateIds(transitStateCollection, idContainer);
            AddStateOfExportIds(stateOfExport, idContainer);
            AddStateOfImportIds(stateOfImport, idContainer);

            var competentAuthorities = await competentAuthorityRepository.GetByIds(idContainer.CompetentAuthorityIds);
            var entryOrExitPoints = await entryOrExitPointRepository.GetByIds(idContainer.EntryOfExitPointIds);
            var lookups = new TransportRouteLookups(countries, competentAuthorities, entryOrExitPoints);

            // Use the loaded competent authorities and entry or exit points to retrieve names for summary data.
            return new TransportRouteData(GenerateTransitStates(transitStateCollection, lookups),
                GenerateStateOfExport(stateOfExport, lookups),
                GenerateStateOfImport(stateOfImport, lookups),
                transitStateCollection.HasNoTransitStates);
        }
Example #5
0
        private IList <TransitState> GenerateTransitStates(Draft.TransitStateCollection transitStates,
                                                           TransportRouteLookups lookups)
        {
            if (transitStates == null || transitStates.TransitStates == null || transitStates.HasNoTransitStates)
            {
                return(new TransitState[0]);
            }

            return(transitStates.TransitStates.Select(ts => GenerateTransitState(ts, lookups)).ToArray());
        }
        private StateOfExport GenerateStateOfExport(Draft.StateOfExport stateOfExport,
            TransportRouteLookups lookups)
        {
            var returnValue = new StateOfExport();

            if (stateOfExport.CompetentAuthorityId.HasValue)
            {
                var competentAuthority = lookups.GetCompetentAuthority(stateOfExport.CompetentAuthorityId);

                returnValue.CompetentAuthorityName = competentAuthority.Name;
                returnValue.CompetentAuthorityCode = competentAuthority.Code;
            }

            if (stateOfExport.CountryId.HasValue)
            {
                returnValue.CountryName = lookups.GetCountry(stateOfExport.CountryId).Name;
            }

            if (stateOfExport.ExitPointId.HasValue)
            {
                returnValue.ExitPointName = lookups.GetEntryOrExitPoint(stateOfExport.ExitPointId).Name;
            }

            return returnValue;
        }
        private TransitState GenerateTransitState(Draft.TransitState transitState, TransportRouteLookups lookups)
        {
            var returnValue = new TransitState();

            if (transitState.CompetentAuthorityId.HasValue)
            {
                var competentAuthority = lookups.GetCompetentAuthority(transitState.CompetentAuthorityId);

                returnValue.CompetentAuthorityCode = competentAuthority.Code;
                returnValue.CompetentAuthorityName = competentAuthority.Name;
            }

            if (transitState.CountryId.HasValue)
            {
                returnValue.CountryName = lookups.GetCountry(transitState.CountryId).Name;
            }

            if (transitState.EntryPointId.HasValue)
            {
                returnValue.EntryPointName = lookups.GetEntryOrExitPoint(transitState.EntryPointId).Name;
            }

            if (transitState.ExitPointId.HasValue)
            {
                returnValue.ExitPointName = lookups.GetEntryOrExitPoint(transitState.ExitPointId).Name;
            }

            return returnValue;
        }
        private IList<TransitState> GenerateTransitStates(Draft.TransitStateCollection transitStates,
            TransportRouteLookups lookups)
        {
            if (transitStates == null || transitStates.TransitStates == null || transitStates.HasNoTransitStates)
            {
                return new TransitState[0];
            }

            return transitStates.TransitStates.Select(ts => GenerateTransitState(ts, lookups)).ToArray();
        }