Exemplo n.º 1
0
        /// <summary>
        /// Returns PassModel list from Pass list
        /// </summary>
        /// <param name="passes"></param>
        /// <param name="passRepository"></param>
        /// <returns></returns>
        public static List <PassModel> MapToPassModels(
            IEnumerable <Pass> passes,
            IPassRepository passRepository,
            IMapper mapper)
        {
            var passModels = new List <PassModel>();

            foreach (var pass in passes)
            {
                passModels.Add(mapper.Map <PassModel>(pass));
            }

            return(passModels);
        }
Exemplo n.º 2
0
        private void SetSalesAreaPrioritiesStartEndTime(IPassRepository passRepository)
        {
            IEnumerable <Pass> passesWithNullSalesAreaTimes = passRepository
                                                              .GetAll()
                                                              .Where(p => (
                                                                         p.PassSalesAreaPriorities.StartTime is null ||
                                                                         p.PassSalesAreaPriorities.EndTime is null));

            foreach (var pass in passesWithNullSalesAreaTimes)
            {
                pass.PassSalesAreaPriorities.StartTime = new TimeSpan(6, 0, 0);
                pass.PassSalesAreaPriorities.EndTime   = new TimeSpan(5, 59, 59);
                passRepository.Update(pass);
            }
        }
Exemplo n.º 3
0
 public UnitOfWork(ICityRepository cityRepository, IClientRepository clientRepository, IClimateRepository climateRepository,
                   ICountryRepository countryRepository, IDiscountRepository discountRepository, IDurationRepository durationRepository,
                   IHotelRepository hotelRepository, IPassDiscountRepository passDiscountRepository, IPassRepository passRepository,
                   ITourRepository tourRepository, TravelCompanyDBContext context)
 {
     _cityRepository         = cityRepository;
     _clientRepository       = clientRepository;
     _climateRepository      = climateRepository;
     _countryRepository      = countryRepository;
     _discountRepository     = discountRepository;
     _durationRepository     = durationRepository;
     _hotelRepository        = hotelRepository;
     _passDiscountRepository = passDiscountRepository;
     _passRepository         = passRepository;
     _tourRepository         = tourRepository;
     _context = context;
 }
Exemplo n.º 4
0
 public PassesController(
     IScenarioRepository scenarioRepository,
     IPassRepository passRepository,
     IMapper mapper,
     IDataManipulator dataManipulator,
     ISalesAreaRepository salesAreaRepository,
     IIdentityGeneratorResolver identityGeneratorResolver,
     IPassInspectorService passInspectorService)
 {
     _scenarioRepository        = scenarioRepository;
     _passRepository            = passRepository;
     _identityGeneratorResolver = identityGeneratorResolver;
     _mapper               = mapper;
     _dataManipulator      = dataManipulator;
     _salesAreaRepository  = salesAreaRepository;
     _passInspectorService = passInspectorService;
 }
Exemplo n.º 5
0
        public OutputImmutableDataSnapshot(RunWithScenarioReference runWithScenarioRef, IRunRepository runRepository,
                                           IScenarioRepository scenarioRepository, IPassRepository passRepository,
                                           ICampaignRepository campaignRepository, IScheduleRepository scheduleRepository,
                                           ISalesAreaRepository salesAreaRepository, IDemographicRepository demographicRepository,
                                           IProgrammeDictionaryRepository programmeDictionaryRepository, ISpotRepository spotRepository,
                                           IMetadataRepository metadataRepository)
        {
            var runStartDate = new Lazy <DateTime>(() => Run.Value.StartDate.Add(Run.Value.StartTime));
            var runEndDate   = new Lazy <DateTime>(() => DateHelper.ConvertBroadcastToStandard(Run.Value.EndDate, Run.Value.EndTime));

            Run                      = new Lazy <Run>(() => runRepository.Find(runWithScenarioRef.RunId));
            Scenario                 = new Lazy <Scenario>(() => scenarioRepository.Get(runWithScenarioRef.ScenarioId), true);
            ScenarioPasses           = new Lazy <IEnumerable <Pass> >(() => passRepository.FindByScenarioId(runWithScenarioRef.ScenarioId), true);
            AllCampaigns             = new Lazy <IEnumerable <Campaign> >(campaignRepository.GetAll, true);
            AllSalesAreas            = new Lazy <IEnumerable <SalesArea> >(salesAreaRepository.GetAll, true);
            AllDemographics          = new Lazy <IEnumerable <Demographic> >(demographicRepository.GetAll, true);
            AllProgrammeDictionaries = new Lazy <IEnumerable <ProgrammeDictionary> >(programmeDictionaryRepository.GetAll, true);
            BreakTypes               = new Lazy <IEnumerable <string> >(() => metadataRepository.GetByKey(MetaDataKeys.BreakTypes).Select(e => (string)e.Value));

            SpotsForRun = new Lazy <IEnumerable <Spot> >(() =>
            {
                var salesAreaPriorities = Run.Value.SalesAreaPriorities.Count == 0
                    ? AllSalesAreas.Value
                    : AllSalesAreas.Value.Where(sa => Run.Value.SalesAreaPriorities.Find(rsa => rsa.SalesArea == sa.Name) != null);

                return(spotRepository.Search(
                           runStartDate.Value,
                           runEndDate.Value,
                           salesAreaPriorities.Select(sa => sa.Name).ToList()
                           ));
            },
                                                         true
                                                         );

            BreaksForRun = new Lazy <IEnumerable <BreakSimple> >(() =>
                                                                 scheduleRepository.GetScheduleSimpleBreaks(
                                                                     AllSalesAreas.Value.Select(c => c.Name).ToList(),
                                                                     runStartDate.Value,
                                                                     runEndDate.Value
                                                                     ),
                                                                 true
                                                                 );
        }
Exemplo n.º 6
0
 public ScenariosController(
     IRunRepository runRepository,
     IScenarioRepository scenarioRepository,
     IPassRepository passRepository,
     ITenantSettingsRepository tenantSettingsRepository,
     IIdentityGeneratorResolver identityGeneratorResolver,
     IMapper mapper,
     ICampaignRepository campaignRepository,
     ISalesAreaRepository salesAreaRepository,
     IPassInspectorService passInspectorService)
 {
     _runRepository             = runRepository;
     _scenarioRepository        = scenarioRepository;
     _passRepository            = passRepository;
     _tenantSettingsRepository  = tenantSettingsRepository;
     _identityGeneratorResolver = identityGeneratorResolver;
     _mapper               = mapper;
     _campaignRepository   = campaignRepository;
     _salesAreaRepository  = salesAreaRepository;
     _passInspectorService = passInspectorService;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Returns ScenarioModel list from Scenario list
        /// </summary>
        /// <param name="scenarios"></param>
        /// <param name="scenarioRepository"></param>
        /// <param name="passRepository"></param>
        /// <param name="tenantSettingsRepository"></param>
        /// <returns></returns>
        public static List <ScenarioModel> MapToScenarioModels(
            List <Scenario> scenarios,
            IScenarioRepository scenarioRepository,
            IPassRepository passRepository,
            ITenantSettingsRepository tenantSettingsRepository,
            IMapper mapper)
        {
            var scenarioModels     = new List <ScenarioModel>();
            var passIdsInScenarios = scenarios
                                     .SelectMany(s => s.Passes)
                                     .Select(p => p.Id);

            var passes = passRepository.GetAll().Where(p => passIdsInScenarios.Contains(p.Id)).ToList();

            var defaultScenarioId = tenantSettingsRepository.Get().DefaultScenarioId;

            scenarios.ForEach(scenario => scenarioModels.Add(mapper.Map <ScenarioModel>(
                                                                 Tuple.Create(scenario, passes, defaultScenarioId))));

            return(scenarioModels);
        }
Exemplo n.º 8
0
 public SqlBulkCampaignCreatedOrUpdatedEventHandler(
     ICampaignCleaner campaignCleaner,
     ICampaignRepository campaignRepository,
     IMapper mapper,
     IScenarioRepository scenarioRepository,
     IPassRepository passRepository,
     ISqlServerDbContextFactory <ISqlServerTenantDbContext> dbContextFactory,
     ISqlServerSalesAreaByNullableIdCacheAccessor salesAreaByIdCache,
     ISqlServerSalesAreaByNameCacheAccessor salesAreaByNameCache
     )
 {
     _campaignCleaner  = campaignCleaner;
     _mapper           = mapper;
     _dbContextFactory = dbContextFactory;
     _campaignPassPrioritiesService = new CampaignPassPrioritiesService(
         campaignRepository,
         mapper,
         passRepository,
         scenarioRepository);
     _salesAreaByIdCache   = salesAreaByIdCache;
     _salesAreaByNameCache = salesAreaByNameCache;
 }
Exemplo n.º 9
0
 public PassService(IPassRepository iRespository)
 {
     _iRespository = iRespository;
 }
Exemplo n.º 10
0
 public PassService(IUnitOfWork unitOfWork)
 {
     _unit       = unitOfWork;
     _repository = _unit.PassRepository;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Returns PassModel from Pass
        /// </summary>
        /// <param name="pass"></param>
        /// <param name="passRepository"></param>
        /// <returns></returns>
        public static PassModel MapToPassModel(Pass pass, IPassRepository passRepository, IMapper mapper)
        {
            var passModel = mapper.Map <PassModel>(pass);

            return(passModel);
        }
Exemplo n.º 12
0
 public PassDomainModelHandler(IPassRepository repository, ISqlServerDbContext dbContext)
 {
     _repository = repository ?? throw new ArgumentNullException(nameof(repository));
     _dbContext  = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
 }
Exemplo n.º 13
0
        /// <summary>
        /// Returns RunModel for run
        /// </summary>
        /// <param name="run"></param>
        /// <param name="scenarioRepository"></param>
        /// <param name="passRepository"></param>
        /// <param name="tenantSettingsRepository"></param>
        /// <param name="allCampaigns"></param>
        /// <param name="functionalAreaRepository"></param>
        /// <returns></returns>
        public static RunModel MapToRunModel(Run run, IScenarioRepository scenarioRepository, IPassRepository passRepository,
                                             ITenantSettingsRepository tenantSettingsRepository, IMapper mapper,
                                             IAnalysisGroupRepository analysisGroupRepository,
                                             IFunctionalAreaRepository functionalAreaRepository = null,
                                             IScenarioCampaignMetricRepository scenarioCampaignMetricRepository = null,
                                             List <CampaignWithProductFlatModel> allCampaigns = null,
                                             List <Pass> passesFromDb = null, List <Scenario> scenariosFromDb = null)
        {
            // Get scenarios for run
            var scenarios = scenariosFromDb ?? scenarioRepository.FindByIds(run.Scenarios.Select(s => s.Id)).ToList();

            // Get passes for run
            var passes = passesFromDb ?? passRepository.FindByIds(scenarios.SelectMany(s => s.Passes).Select(p => p.Id).Distinct()).ToList();

            var analysisGroups = run.AnalysisGroupTargets.Any()
                ? analysisGroupRepository.GetByIds(run.AnalysisGroupTargets.Select(x => x.AnalysisGroupId).ToArray()).ToDictionary(x => x.Id)
                : new Dictionary <int, AnalysisGroupNameModel>();

            // Get default ScenarioId
            var defaultScenarioId = tenantSettingsRepository.GetDefaultScenarioId();

            if (run.RunStatus == RunStatus.NotStarted && allCampaigns != null && allCampaigns.Any())
            {
                // Since the run has not already started amend Run Scenarios
                // with CampaignPassPriorities for new Campaigns and remove
                // CampaignPassPriorities of deleted Campaigns
                CampaignPassPrioritiesServiceMapper.AmendCampaignPassPriorities(
                    scenarios,
                    passes,
                    allCampaigns,
                    passRepository,
                    mapper);
            }

            var runModel = mapper.Map <RunModel>(Tuple.Create(run, scenarios, passes, analysisGroups, defaultScenarioId));

            if (run.RunStatus == RunStatus.Complete)
            {
                ApplyFunctionalAreaFaultTypesToRunModel(runModel, run, functionalAreaRepository);
            }

            if (scenarioCampaignMetricRepository != null)
            {
                runModel.Scenarios.ForEach(s => ApplyKPIsToScenarioCampaigns(s, scenarioCampaignMetricRepository));
            }

            return(runModel);
        }
Exemplo n.º 14
0
 public PassService(IPassRepository passRepository, IPassDescriptionRepository passDescriptionRepository, IPassActivePTOMapper passActivePTOMapper, IJwtFactory jwtFactory, IMessageHandler messageHandler, ILoggerManager logger, IMapper mapper) : base(messageHandler, mapper, logger, jwtFactory)
 {
     _passRepository            = passRepository;
     _passDescriptionRepository = passDescriptionRepository;
     _passActivePTOMapper       = passActivePTOMapper;
 }
Exemplo n.º 15
0
        public static void AmendCampaignPassPrioritiesForNewCampaigns(
            Scenario inScenario,
            List <Pass> forAllScenariosPasses,
            Dictionary <string, CampaignWithProductFlatModel> usingAllCampaigns,
            IPassRepository passRepository,
            IMapper mapper)
        {
            if (
                inScenario?.IsLibraried == null ||
                !inScenario.IsLibraried.Value ||
                usingAllCampaigns?.Any() != true
                )
            {
                return;
            }

            // Get all campaign external ids from existing campaign pass
            // priorities in the scenario
            HashSet <string> existingCppCampaignExternalIds = null;

            if (inScenario.CampaignPassPriorities != null)
            {
                existingCppCampaignExternalIds = new HashSet <string>();

                foreach (var campaignPassPriority in inScenario.CampaignPassPriorities)
                {
                    if (campaignPassPriority?.Campaign == null)
                    {
                        continue;
                    }

                    existingCppCampaignExternalIds.Add(campaignPassPriority.Campaign.ExternalId);

                    if (!usingAllCampaigns.ContainsKey(campaignPassPriority.Campaign.ExternalId))
                    {
                        continue;
                    }

                    var campaign =
                        mapper.Map <CompactCampaign>(usingAllCampaigns[campaignPassPriority.Campaign.ExternalId]);

                    if (campaign != null && !campaign.Equals(campaignPassPriority.Campaign))
                    {
                        campaignPassPriority.Campaign = campaign;
                    }
                }
            }

            // Get the pass details for the existing Scenario passes
            var existingScenarioPassIds = inScenario.Passes.Select(p => p.Id).ToList();
            var existingScenarioPasses  = forAllScenariosPasses?.Any() == true?
                                          forAllScenariosPasses.Where(p => existingScenarioPassIds.Contains(p.Id)).ToList() :
                                              passRepository?.FindByIds(existingScenarioPassIds).ToList();

            var existingCampaigns = usingAllCampaigns.Values.ToList();

            // Create CampaignPassPriorities for the new campaigns which are not
            // in the campaignPassPriorities
            var campaignPassPrioritiesForNewCampaigns =
                CreateCampaignPassPriorities(
                    existingCampaigns,
                    existingCppCampaignExternalIds,
                    existingScenarioPasses, mapper);

            if (campaignPassPrioritiesForNewCampaigns?.Any() == true)
            {
                // Apply new Campaign Pass Priorities to the Scenario
                var newCppList =
                    MapToCampaignPassPriorities(
                        campaignPassPrioritiesForNewCampaigns,
                        existingCampaigns,
                        mapper);
                inScenario.CampaignPassPriorities ??= new List <CampaignPassPriority>();
                inScenario.CampaignPassPriorities.AddRange(newCppList);
            }
        }
Exemplo n.º 16
0
 public TravellerService(ITravellerRepository travellerRepository, IPassRepository passRepository, IJwtFactory jwtFactory, IMessageHandler messageHandler, ILoggerManager logger, IMapper mapper) : base(messageHandler, mapper, logger, jwtFactory)
 {
     _travellerRepository = travellerRepository;
     _passRepository      = passRepository;
 }
Exemplo n.º 17
0
 public PassService(IPassRepository passRepository)
 {
     _passRepository = passRepository;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Returns ScenarioModel from Scenario
        /// </summary>
        /// <param name="scenario"></param>
        /// <param name="scenarioRepository"></param>
        /// <param name="passRepository"></param>
        /// <param name="tenantSettingsRepository"></param>
        /// <returns></returns>
        public static ScenarioModel MapToScenarioModel(Scenario scenario, IScenarioRepository scenarioRepository, IPassRepository passRepository,
                                                       ITenantSettingsRepository tenantSettingsRepository, IMapper mapper)
        {
            // Get passes
            List <Pass> passes = passRepository.FindByIds(scenario.Passes.Select(p => p.Id)).ToList();

            // Get default ScenarioId
            var defaultScenarioId = tenantSettingsRepository.Get().DefaultScenarioId;

            var scenarioModel = mapper.Map <ScenarioModel>(Tuple.Create(scenario, passes, defaultScenarioId));

            return(scenarioModel);
        }