示例#1
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.");
            }
        }