Пример #1
0
        public async Task <IActionResult> CreateLeague([FromBody] CreateLeagueRequest request)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

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

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

            if (!request.ValidForOldYears())
            {
                return(BadRequest());
            }

            var supportedYears = await _interLeagueService.GetSupportedYears();

            var selectedSupportedYear = supportedYears.SingleOrDefault(x => x.Year == request.InitialYear);

            if (selectedSupportedYear is null)
            {
                return(BadRequest());
            }

            var userIsBetaUser = await _userManager.IsInRoleAsync(currentUser, "BetaTester");

            bool yearIsOpen = selectedSupportedYear.OpenForCreation || (userIsBetaUser && selectedSupportedYear.OpenForBetaUsers);

            if (!yearIsOpen)
            {
                return(BadRequest());
            }

            EligibilityLevel eligibilityLevel = await _interLeagueService.GetEligibilityLevel(request.MaximumEligibilityLevel);

            LeagueCreationParameters domainRequest = request.ToDomain(currentUser, eligibilityLevel);
            var league = await _fantasyCriticService.CreateLeague(domainRequest);

            if (league.IsFailure)
            {
                return(BadRequest(league.Error));
            }

            return(Ok());
        }
    public async Task <IActionResult> CreateLeague([FromBody] CreateLeagueRequest request)
    {
        var currentUserResult = await GetCurrentUser();

        if (currentUserResult.IsFailure)
        {
            return(BadRequest(currentUserResult.Error));
        }
        var currentUser = currentUserResult.Value;

        var requestValid = request.IsValid();

        if (requestValid.IsFailure)
        {
            return(BadRequest(requestValid.Error));
        }

        var supportedYears = await _interLeagueService.GetSupportedYears();

        var selectedSupportedYear = supportedYears.SingleOrDefault(x => x.Year == request.LeagueYearSettings.Year);

        if (selectedSupportedYear is null)
        {
            return(BadRequest("That year is not supported."));
        }

        var userIsBetaUser = await _userManager.IsInRoleAsync(currentUser, "BetaTester");

        bool yearIsOpen = selectedSupportedYear.OpenForCreation || (userIsBetaUser && selectedSupportedYear.OpenForBetaUsers);

        if (!yearIsOpen)
        {
            return(BadRequest("That year is not open for play."));
        }

        var tagDictionary = await _interLeagueService.GetMasterGameTagDictionary();

        LeagueCreationParameters domainRequest = request.ToDomain(currentUser, tagDictionary);
        var league = await _fantasyCriticService.CreateLeague(domainRequest);

        if (league.IsFailure)
        {
            return(BadRequest(league.Error));
        }

        return(Ok());
    }
        public async Task <IActionResult> CreateLeague([FromBody] CreateLeagueRequest request)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

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

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

            EligibilityLevel eligibilityLevel = await _fantasyCriticService.GetEligibilityLevel(request.MaximumEligibilityLevel);

            LeagueCreationParameters domainRequest = request.ToDomain(currentUser, eligibilityLevel);
            await _fantasyCriticService.CreateLeague(domainRequest);

            return(Ok());
        }