Пример #1
0
        public async Task <TransportRouteData> HandleAsync(GetTransportRouteSummaryForNotification message)
        {
            var transportRoute = await repository.GetByNotificationId(message.NotificationId);

            return(new TransportRouteData
            {
                StateOfExportData = transportRoute == null ? null : stateOfExportMapper.Map(transportRoute.StateOfExport),
                StateOfImportData = transportRoute == null ? null : stateOfImportMapper.Map(transportRoute.StateOfImport),
                TransitStatesData = transportRoute == null ? null : transitStateMapper.Map(transportRoute.TransitStates)
            });
        }
        public async Task <Guid> HandleAsync(SetTransitStateForNotification message)
        {
            var transportRoute = await repository.GetByNotificationId(message.NotificationId);

            if (transportRoute == null)
            {
                transportRoute = new TransportRoute(message.NotificationId);
                context.TransportRoutes.Add(transportRoute);
            }

            var country = await context.Countries.SingleAsync(c => c.Id == message.CountryId);

            var competentAuthority =
                await context.CompetentAuthorities.SingleAsync(ca => ca.Id == message.CompetentAuthorityId);

            var entryPoint = await context.EntryOrExitPoints.SingleAsync(ep => ep.Id == message.EntryPointId);

            var exitPoint = await context.EntryOrExitPoints.SingleAsync(ep => ep.Id == message.ExitPointId);

            Guid result;

            if (message.TransitStateId.HasValue)
            {
                transportRoute.UpdateTransitStateForNotification(message.TransitStateId.Value,
                                                                 country,
                                                                 competentAuthority,
                                                                 entryPoint,
                                                                 exitPoint,
                                                                 message.OrdinalPosition);

                result = message.TransitStateId.Value;
            }
            else
            {
                var ordinalPosition = transportRoute.GetAvailableTransitStatePositions().First();
                var transitState    = new TransitState(country, competentAuthority, entryPoint, exitPoint, ordinalPosition);
                result = transitState.Id;
                transportRoute.AddTransitStateToNotification(transitState);
            }

            await context.SaveChangesAsync();

            return(result);
        }
Пример #3
0
        public async Task <Unit> HandleAsync(SetEntryPoint message)
        {
            var intraCountryExportAlloweds = await intraCountryExportAllowedRepository.GetAllAsync();

            var uksAuthorities = await unitedKingdomCompetentAuthorityRepository.GetAllAsync();

            var entryPoint = await entryOrExitPointRepository.GetById(message.EntryPointId);

            var transportRoute = await transportRouteRepository.GetByNotificationId(message.NotificationId);

            var validator = new TransportRouteValidation(intraCountryExportAlloweds, uksAuthorities);

            transportRoute.SetStateOfImportForNotification(new StateOfImport(transportRoute.StateOfImport.Country,
                                                                             transportRoute.StateOfImport.CompetentAuthority, entryPoint), validator);

            await context.SaveChangesAsync();

            return(Unit.Value);
        }
        public async Task <TransitStateWithTransportRouteData> HandleAsync(GetTransitStateWithTransportRouteDataByNotificationId message)
        {
            var countries = (await countryRepository.GetAllHavingCompetentAuthorities())
                            .Select(c => mapper.Map <CountryData>(c))
                            .ToArray();

            var transportRoute = await transportRouteRepository.GetByNotificationId(message.Id);

            if (transportRoute == null)
            {
                return(new TransitStateWithTransportRouteData
                {
                    Countries = countries
                });
            }

            var data = new TransitStateWithTransportRouteData
            {
                Countries     = countries,
                StateOfExport = mapper.Map <StateOfExportData>(transportRoute.StateOfExport),
                StateOfImport = mapper.Map <StateOfImportData>(transportRoute.StateOfImport),
                TransitStates = transportRoute.TransitStates.Select(t => mapper.Map <TransitStateData>(t)).ToArray()
            };

            var thisTransitState = transportRoute.TransitStates.SingleOrDefault(ts => ts.Id == message.TransitStateId);

            if (thisTransitState != null)
            {
                var competentAuthorities =
                    await competentAuthorityRepository.GetTransitAuthorities(thisTransitState.Country.Id);

                var entryPoints = await context.EntryOrExitPoints.Where(ep => ep.Country.Id == thisTransitState.Country.Id).ToArrayAsync();

                data.CompetentAuthorities = competentAuthorities.Select(ca => mapper.Map <CompetentAuthorityData>(ca)).ToArray();
                data.EntryOrExitPoints    = entryPoints.Select(e => mapper.Map <EntryOrExitPointData>(e)).ToArray();
                data.TransitStates        = data.TransitStates.Where(ts => ts.Id != thisTransitState.Id).ToArray();
                data.TransitState         = mapper.Map <TransitStateData>(thisTransitState);
            }

            return(data);
        }
        public async Task <StateOfImportWithTransportRouteData> HandleAsync(GetStateOfImportWithTransportRouteDataByNotificationId message)
        {
            var transportRoute = await transportRouteRepository.GetByNotificationId(message.Id);

            var countries = await countryRepository.GetAllHavingCompetentAuthorities();

            var notification = await notificationApplicationRepository.GetById(message.Id);

            var allowed = await intraCountryExportAllowedRepository.GetImportCompetentAuthorities(notification.CompetentAuthority);

            if (!allowed.Any())
            {
                // Need to remove the UK from the list
                var unitedkingdomId = (await this.unitedKingdomCompetentAuthorityRepository.GetByCompetentAuthority(notification.CompetentAuthority)).CompetentAuthority.Country.Id;
                countries = countries.Where(c => c.Id != unitedkingdomId);
            }

            var data = new StateOfImportWithTransportRouteData();

            if (transportRoute != null)
            {
                data.StateOfImport = mapper.Map <StateOfImportData>(transportRoute.StateOfImport);
                data.StateOfExport = mapper.Map <StateOfExportData>(transportRoute.StateOfExport);
                data.TransitStates = transportRoute.TransitStates.Select(t => mapper.Map <TransitStateData>(t)).ToList();

                if (transportRoute.StateOfImport != null)
                {
                    var selectedCountryModel   = new GetCompetentAuthoritiesAndEntryPointsByCountryId(transportRoute.StateOfImport.Country.Id, notification.CompetentAuthority);
                    var dataForSelectedCountry = await this.getCompetentAuthoritiesAndEntryPointsByCountryIdHandler.HandleAsync(selectedCountryModel);

                    data.CompetentAuthorities = dataForSelectedCountry.CompetentAuthorities;
                    data.EntryPoints          = dataForSelectedCountry.EntryOrExitPoints;
                }

                data.IntraCountryExportAllowed = allowed.Select(a => mapper.Map <IntraCountryExportAllowedData>(a)).ToArray();
            }

            data.Countries = countries.Select(c => mapper.Map <CountryData>(c)).ToArray();

            return(data);
        }
        public async Task <bool> HandleAsync(SetEntryCustomsOfficeSelectionForNotificationById message)
        {
            var transportRoute = await repository.GetByNotificationId(message.Id);

            var requiredCustomsOffices = new RequiredCustomsOffices();

            if (transportRoute == null)
            {
                transportRoute = new TransportRoute(message.Id);
                context.TransportRoutes.Add(transportRoute);
            }

            bool?existingExit = transportRoute.EntryExitCustomsOfficeSelection != null ? transportRoute.EntryExitCustomsOfficeSelection.Exit : null;

            var selection = new EntryExitCustomsOfficeSelection(message.Selection, existingExit);

            transportRoute.SetEntryExitCustomsOfficeSelection(selection);

            await context.SaveChangesAsync();

            return(true);
        }
Пример #7
0
        public async Task <IDocumentBlock> Create(Guid notificationId, IList <MergeField> mergeFields)
        {
            var transportRoute = await transportRouteRepository.GetByNotificationId(notificationId);

            return(new TransportBlock(mergeFields, transportRoute));
        }
Пример #8
0
        public async Task <StateOfExportData> HandleAsync(GetStateOfExportData message)
        {
            var transportRoute = await transportRouteRepository.GetByNotificationId(message.NotificationId);

            return(mapper.Map <StateOfExportData>(transportRoute.StateOfExport));
        }
        public async Task <ExitCustomsOfficeAddData> HandleAsync(GetExitCustomsOfficeAddDataByNotificationId message)
        {
            var transportRoute = await repository.GetByNotificationId(message.Id);

            return(customsOfficeExitMap.Map(transportRoute));
        }