Beispiel #1
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));
        }
Beispiel #2
0
 private void AddStateOfImportIds(Draft.StateOfImport stateOfImport, TransportRouteIdContainer idContainer)
 {
     if (stateOfImport != null)
     {
         idContainer.AddCompetentAuthority(stateOfImport.CompetentAuthorityId);
         idContainer.AddEntryOrExitPoint(stateOfImport.EntryPointId);
     }
 }
Beispiel #3
0
 private void AddTransitStateIds(Draft.TransitStateCollection transitStateCollection,
                                 TransportRouteIdContainer idContainer)
 {
     if (transitStateCollection != null && transitStateCollection.TransitStates != null)
     {
         idContainer.AddCompetentAuthorities(transitStateCollection.TransitStates.Select(ts => ts.CompetentAuthorityId));
         idContainer.AddEntryOrExitPoints(transitStateCollection.TransitStates.Select(ts => ts.EntryPointId));
         idContainer.AddEntryOrExitPoints(transitStateCollection.TransitStates.Select(ts => ts.ExitPointId));
     }
 }