Exemplo n.º 1
0
        public async Task RemovePrizeAsync(int prizeWinnerId)
        {
            VerifyManagementPermission();

            int authUserId = GetClaimId(ClaimType.UserId);
            var prize      = await _prizeWinnerRepository.GetByIdAsync(prizeWinnerId);

            if (!prize.RedeemedAt.HasValue)
            {
                await _prizeWinnerRepository.RemoveSaveAsync(authUserId, prizeWinnerId);

                if (prize.DrawingId.HasValue)
                {
                    var winnerCount = await _drawingRepository.GetWinnerCountAsync(
                        prize.DrawingId.Value);

                    if (winnerCount == 0)
                    {
                        await _drawingRepository.SetArchivedAsync(authUserId, prize.DrawingId.Value,
                                                                  true);
                    }
                }
            }
            else
            {
                _logger.LogError($"User {authUserId} cannot remove claimed prize {prize.Id}.");
                throw new GraException("Prizes that have been claimed cannot be removed.");
            }
        }
Exemplo n.º 2
0
        public async Task RemoveWinnerAsync(int drawingId, int userId)
        {
            int authUserId = GetClaimId(ClaimType.UserId);

            if (HasPermission(Permission.PerformDrawing))
            {
                var winner = await _drawingRepository.GetDrawingWinnerById(drawingId, userId);

                if (!winner.RedeemedAt.HasValue)
                {
                    await _drawingRepository.RemoveWinnerAsync(drawingId, userId);

                    var winnerCount = await _drawingRepository.GetWinnerCountAsync(drawingId);

                    if (winnerCount == 0)
                    {
                        await _drawingRepository.SetArchivedAsync(authUserId, drawingId, true);
                    }
                }
                else
                {
                    _logger.LogError($"User {authUserId} cannot remove user {userId} from drawing {drawingId}.");
                    throw new GraException("Winners who have claimed their prize cannot be removed.");
                }
            }
            else
            {
                _logger.LogError($"User {authUserId} doesn't have permission to remove user {userId} from drawing {drawingId}.");
                throw new GraException("Permission denied.");
            }
        }