public async Task Handle(IncrementSelfOwnershipWeekCounter notification, CancellationToken cancellationToken)
        {
            var plEntry = await _repo.GetVerifiedPLEntry(notification.EntryId);

            var selfOwnership = plEntry.SelfOwnershipStats with {
                WeekCount = plEntry.SelfOwnershipStats.WeekCount + 1
            };
            await _repo.UpdateStats(notification.EntryId, selfOwnership);
        }
    }
Example #2
0
    public async Task Handle(IncrementPointsFromSelfOwnership notification, CancellationToken cancellationToken)
    {
        var plEntry = await _repo.GetVerifiedPLEntry(notification.EntryId);

        var newPoints     = plEntry.SelfOwnershipStats.TotalPoints + notification.PointsFromSelf;
        var selfOwnership = plEntry.SelfOwnershipStats with {
            TotalPoints = newPoints
        };
        await _repo.UpdateStats(notification.EntryId, selfOwnership);
    }
}
Example #3
0
    public async Task <IActionResult> GetPL(int entryId)
    {
        var plVerifiedEntry = await _plRepo.GetVerifiedPLEntry(entryId);

        if (plVerifiedEntry == null)
        {
            return(NotFound());
        }

        var verifiedEntry = await _repo.GetVerifiedEntry(entryId);

        if (verifiedEntry == null)
        {
            return(NotFound());
        }

        return(Ok(ApiModelBuilder.BuildPLEntry(verifiedEntry, plVerifiedEntry)));
    }
Example #4
0
    public async Task Handle(SeedSelfishness message, IMessageHandlerContext context)
    {
        using var scope = _logger.BeginScope(new Dictionary <string, object> {
            ["Entry"] = message.EntryId
        });
        var verifiedPlEntry = await _plRepo.GetVerifiedPLEntry(message.EntryId);

        var settings = await _settingsClient.GetGlobalSettings();

        var allPlayers        = settings.Players;
        var currentGameweekId = settings.Gameweeks.GetCurrentGameweek().Id;
        var liveItems         = await GetAllLiveItems(currentGameweekId);

        var player        = allPlayers.Get(verifiedPlEntry.PlayerId);
        var selfOwnership = (await _calculator.CalculateSelfOwnershipPoints(verifiedPlEntry.EntryId, player.Id, Enumerable.Range(1, currentGameweekId), liveItems)).ToArray();
        await _plRepo.UpdateStats(verifiedPlEntry.EntryId, verifiedPlEntry.SelfOwnershipStats with
        {
            TotalPoints = selfOwnership.Sum(),
            WeekCount   = selfOwnership.Length,
            Gameweek    = currentGameweekId
        });