Example #1
0
        public async Task <Guid> HandleAsync(SetStateOfImportForNotification 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.EntryOrExitPointId);

            var stateOfImport = new StateOfImport(country, competentAuthority, entryPoint);

            var acceptableImportStates = await iceaRepository.GetAllAsync();

            var validator = new TransportRouteValidation(await iceaRepository.GetAllAsync(),
                                                         await this.context.UnitedKingdomCompetentAuthorities.ToArrayAsync());

            transportRoute.SetStateOfImportForNotification(stateOfImport, validator);

            await context.SaveChangesAsync();

            return(stateOfImport.Id);
        }
        public async Task <Guid> HandleAsync(SetStateOfExportForNotification message)
        {
            var notification = await context.GetNotificationApplication(message.NotificationId);

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

            var country = await context.Countries.SingleAsync(c => c.Name == UnitedKingdomCompetentAuthority.CountryName);

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

            var acceptableExportStates = await iceaRepository.GetAllAsync();

            var unitedKingdomAuthorities = await context.UnitedKingdomCompetentAuthorities.ToArrayAsync();

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

            var ukcompAuth = await unitedKingdomCompetentAuthorityRepository.GetByCompetentAuthority(notification.CompetentAuthority);

            var caid = ukcompAuth.CompetentAuthority.Id;
            var competentAuthority = await context.CompetentAuthorities.SingleAsync(ca => ca.Id == caid);

            var stateOfExport = new StateOfExport(country, competentAuthority, exitPoint);
            var validator     = new TransportRouteValidation(acceptableExportStates, unitedKingdomAuthorities);

            transportRoute.SetStateOfExportForNotification(stateOfExport, validator);

            await context.SaveChangesAsync();

            return(stateOfExport.Id);
        }
Example #3
0
        private async Task <TransportRoute> CloneTransportRoute(Guid sourceNotificationId, Guid destinationNotificationId, UKCompetentAuthority destinationCompetentAuthority)
        {
            var transportRoute = await context.TransportRoutes.SingleOrDefaultAsync(p => p.NotificationId == sourceNotificationId);

            var destinationTransportRoute = new TransportRoute(destinationNotificationId);

            if (transportRoute != null)
            {
                var sourceCompetentAuthority   = (await notificationApplicationRepository.GetById(sourceNotificationId)).CompetentAuthority;
                var intraCountryExportAlloweds = await intraCountryExportAllowedRepository.GetAllAsync();

                if (destinationCompetentAuthority == sourceCompetentAuthority)
                {
                    transportRouteCopier.CopyTransportRoute(transportRoute, destinationTransportRoute, intraCountryExportAlloweds);
                }
                else
                {
                    transportRouteCopier.CopyTransportRouteWithoutExport(transportRoute, destinationTransportRoute, intraCountryExportAlloweds);
                }
            }

            context.TransportRoutes.Add(destinationTransportRoute);

            await context.SaveChangesAsync();

            return(destinationTransportRoute);
        }
Example #4
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);
        }