public async Task <IActionResult> ChangeLeagueOptions([FromBody] ChangeLeagueOptionsRequest request)
    {
        var leagueRecord = await GetExistingLeague(request.LeagueID, RequiredRelationship.LeagueManager);

        if (leagueRecord.FailedResult is not null)
        {
            return(leagueRecord.FailedResult);
        }
        var validResult = leagueRecord.ValidResult !;
        var league      = validResult.League;

        if (string.IsNullOrWhiteSpace(request.LeagueName))
        {
            return(BadRequest("You cannot have a blank league name."));
        }

        bool testLeague = request.TestLeague;

        if (league.TestLeague)
        {
            //Users can't change a test league to a non test.
            testLeague = true;
        }

        await _fantasyCriticService.ChangeLeagueOptions(league, request.LeagueName, request.PublicLeague, testLeague);

        return(Ok());
    }
Beispiel #2
0
        public async Task <IActionResult> ChangeLeagueOptions([FromBody] ChangeLeagueOptionsRequest request)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            if (currentUser == null)
            {
                return(BadRequest());
            }

            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());
            }

            if (league.Value.TestLeague)
            {
                //Users can't change a test league to a non test.
                request.TestLeague = true;
            }

            await _fantasyCriticService.ChangeLeagueOptions(league.Value, request.LeagueName, request.PublicLeague, request.TestLeague);

            return(Ok());
        }