示例#1
0
        public async Task <IActionResult> SetDraftPause([FromBody] DraftPauseRequest request)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var league = await _fantasyCriticService.GetLeagueByID(request.LeagueID);

            if (league.HasNoValue)
            {
                return(BadRequest());
            }

            if (league.Value.LeagueManager.UserID != currentUser.UserID)
            {
                return(Forbid());
            }

            var leagueYear = await _fantasyCriticService.GetLeagueYear(league.Value.LeagueID, request.Year);

            if (leagueYear.HasNoValue)
            {
                return(BadRequest());
            }

            if (request.Pause)
            {
                if (!leagueYear.Value.PlayStatus.Equals(PlayStatus.Drafting))
                {
                    return(BadRequest());
                }
            }
            if (!request.Pause)
            {
                if (!leagueYear.Value.PlayStatus.Equals(PlayStatus.DraftPaused))
                {
                    return(BadRequest());
                }
            }

            await _draftService.SetDraftPause(leagueYear.Value, request.Pause);

            await _hubContext.Clients.Group(leagueYear.Value.GetGroupName).SendAsync("RefreshLeagueYear");

            return(Ok());
        }
    public async Task <IActionResult> SetDraftPause([FromBody] DraftPauseRequest request)
    {
        var leagueYearRecord = await GetExistingLeagueYear(request.LeagueID, request.Year, ActionProcessingModeBehavior.Allow, RequiredRelationship.LeagueManager, RequiredYearStatus.DuringDraft);

        if (leagueYearRecord.FailedResult is not null)
        {
            return(leagueYearRecord.FailedResult);
        }
        var validResult = leagueYearRecord.ValidResult !;
        var leagueYear  = validResult.LeagueYear;

        await _draftService.SetDraftPause(leagueYear, request.Pause);

        await _hubContext.Clients.Group(leagueYear.GetGroupName).SendAsync("RefreshLeagueYear");

        return(Ok());
    }