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