Example #1
0
    public async Task Handle(ConnectEntryToPLPlayer notification, CancellationToken cancellationToken)
    {
        var settings = await _settings.GetGlobalSettings();

        _logger.LogInformation($"Inserting hardcoded list");

        var allTeams   = settings.Teams.ToList();
        var allPlayers = settings.Players.ToList();

        var plPlayer = allPlayers.Get(notification.PlayerId);

        if (plPlayer != null)
        {
            _logger.LogInformation($"FOUND PLAYER {plPlayer.WebName}, INSERTING PL ENTRY {notification.EntryId}");
            var teamForPLEntry = allTeams.Get(plPlayer.TeamId);

            await _repo.Insert(new VerifiedPLEntry(
                                   EntryId : notification.EntryId,
                                   TeamId : teamForPLEntry.Id,
                                   TeamCode : teamForPLEntry.Code,
                                   TeamName : teamForPLEntry.Name,
                                   PlayerId : plPlayer.Id,
                                   PlayerCode : plPlayer.Code,
                                   PlayerWebName : plPlayer.WebName,
                                   PlayerFullName : plPlayer.FullName
                                   ));

            _logger.LogInformation($"{notification.EntryId} inserted");

            if (notification.Gameweek.HasValue)
            {
                await _mediator.Publish(new UpdateSelfishStatsForPLEntry(notification.Gameweek.Value, notification.EntryId), cancellationToken);
            }
        }
        else
        {
            _logger.LogError($"PL Player {plPlayer.Id} not found");
        }
    }