Exemplo n.º 1
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());
        }