public async Task <IActionResult> GetMarketTypesByCompetition(int dataProviderId, string eventTypeId, string competitionId)
        {
            DataProvider dataProvider = await _dataProviderReader.Read(dataProviderId);

            if (dataProvider == null)
            {
                return(NotFound($"Unable to find dataProvider with id {dataProviderId}"));
            }

            IExternalEventTypesRepository eventTypesRepository = _eventTypesRepositoryFactory?.Invoke(dataProviderId);
            EventType eventType = await eventTypesRepository.GetEventType(eventTypeId);

            if (eventType == null)
            {
                return(NotFound($"Unable to find event type with id {eventTypeId}"));
            }

            IExternalCompetitionsRepository competitionsRepository = _competitionsRepositoryFactory?.Invoke(dataProviderId);
            Competition competition = await competitionsRepository.GetCompetition(competitionId);

            if (competition == null)
            {
                return(NotFound($"Unable to find competition with id {competitionId}"));
            }

            IExternalMarketTypesRepository marketTypesRepository = _marketTypesRepositoryFactory?.Invoke(dataProviderId);
            IEnumerable <MarketType>       marketTypes           = await marketTypesRepository.GetMarketTypesByCompetitionId(competitionId);

            return(Ok(marketTypes));
        }
Example #2
0
        public async Task <IActionResult> GetEventTypes(int dataProviderId)
        {
            IExternalEventTypesRepository repository = _repositoryFactory?.Invoke(dataProviderId);

            if (repository == null)
            {
                return(NotFound($"Unable to find data provider with id of {dataProviderId}"));
            }

            IEnumerable <EventType> eventTypes = await repository.GetEventTypes();

            return(Ok(eventTypes));
        }
        public async Task <IActionResult> GetCompetitionsByEventType(int dataProviderId, string eventTypeId)
        {
            IExternalEventTypesRepository eventTypesRepository = _eventTypesRepositoryFactory?.Invoke(dataProviderId);

            if (eventTypesRepository == null)
            {
                return(NotFound($"Unable to find data provider with id of {dataProviderId}"));
            }

            EventType eventType = await eventTypesRepository.GetEventType(eventTypeId);

            if (eventType == null)
            {
                return(NotFound($"Could not find event type with id of {eventTypeId} for data provider with id {dataProviderId}"));
            }

            IExternalCompetitionsRepository competitionsRepository = _competitionsRepositoryFactory?.Invoke(dataProviderId);
            IEnumerable <Competition>       competitions           = await competitionsRepository.GetCompetitionsByEventType(eventTypeId);

            return(Ok(competitions));
        }
Example #4
0
        public async Task DoWork(CompetitionMarketType competitionMarketType)
        {
            DataProvider externalDataProvider = await _externalDataProviderReader.Read(competitionMarketType.DataProviderId);

            if (externalDataProvider == null)
            {
                throw new Exception($"No data provider found with id of {competitionMarketType.DataProviderId}");
            }
            Domain.Internal.DataProvider dataProvider = _mapper.Map <Domain.Internal.DataProvider>(externalDataProvider);
            await _upserter.Upsert(dataProvider);

            IExternalCompetitionsRepository competitionsRepository = _externalCompetitionsRepositoryFactory?.Invoke(competitionMarketType.DataProviderId);
            Competition externalCompetition = await competitionsRepository.GetCompetition(competitionMarketType.CompetitionId);

            if (externalCompetition == null)
            {
                throw new Exception($"No competition found with id of {competitionMarketType.CompetitionId}");
            }

            IExternalMarketTypesRepository marketTypesRepository = _externalMarketTypesRepositoryFactory?.Invoke(competitionMarketType.DataProviderId);
            MarketType marketTypeForCompetition = await marketTypesRepository.GetMarketTypeForCompetition(
                competitionMarketType.CompetitionId,
                competitionMarketType.MarketType);

            if (marketTypeForCompetition == null)
            {
                throw new Exception($"No {competitionMarketType.MarketType} market type found for competition with id {competitionMarketType.CompetitionId}");
            }

            IExternalEventTypesRepository eventTypesRepository = _externalEventTypesRepositoryFactory?.Invoke(competitionMarketType.DataProviderId);
            EventType externalEventType = await eventTypesRepository.GetEventTypeForCompetition(competitionMarketType.CompetitionId);

            if (externalEventType != null)
            {
                Domain.Internal.EventType eventType = _mapper.Map <Domain.Internal.EventType>(externalEventType);
                await _upserter.Upsert(eventType);
            }

            Domain.Internal.Competition competition = _mapper.Map <Domain.Internal.Competition>(externalCompetition);
            if (competition != null)
            {
                competition.EventTypeId = externalEventType?.Id;
                await _upserter.Upsert(competition);
            }
            IExternalEventsRepository eventsRepository = _externalEventsRepositoryFactory?.Invoke(competitionMarketType.DataProviderId);
            IEnumerable <Event>       events           = await eventsRepository.GetEventsByCompetitionIdAndMarketType(
                competitionMarketType.CompetitionId,
                competitionMarketType.MarketType);

            foreach (var externalEvent in events ?? new Event[0])
            {
                Domain.Internal.Event internalEvent = _mapper.Map <Domain.Internal.Event>(externalEvent);
                if (internalEvent != null)
                {
                    internalEvent.CompetitionId = competition?.Id;
                    await _upserter.Upsert(internalEvent);
                }

                IExternalMarketsRepository marketsRepository = _externalMarketsRepositoryFactory?.Invoke(competitionMarketType.DataProviderId);
                Market externalMarket = await marketsRepository.GetMarketForEventAndMarketType(
                    externalEvent.Id,
                    competitionMarketType.MarketType);

                Domain.Internal.Market market = _mapper.Map <Domain.Internal.Market>(externalMarket);
                if (market != null)
                {
                    market.EventId = internalEvent?.Id;
                    await _upserter.Upsert(market);
                }
                foreach (var externalRunner in externalMarket.Runners)
                {
                    Domain.Internal.Selection selection = _mapper.Map <Domain.Internal.Selection>(externalRunner);
                    if (selection != null)
                    {
                        selection.MarketId = market?.Id;
                        await _upserter.Upsert(selection);
                    }
                }
            }
        }