public async Task <IActionResult> EditLeagueYearSettings([FromBody] LeagueYearSettingsViewModel request)
    {
        var leagueYearRecord = await GetExistingLeagueYear(request.LeagueID, request.Year, ActionProcessingModeBehavior.Ban, RequiredRelationship.LeagueManager, RequiredYearStatus.AnyYearNotFinished);

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

        var requestValid = request.IsValid();

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

        var tagDictionary = await _interLeagueService.GetMasterGameTagDictionary();

        LeagueYearParameters domainRequest = request.ToDomain(tagDictionary);
        Result result = await _fantasyCriticService.EditLeague(leagueYear, domainRequest);

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

        await _fantasyCriticService.UpdatePublisherGameCalculatedStats(leagueYear);

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

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

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

            var systemWideSettings = await _interLeagueService.GetSystemWideSettings();

            if (systemWideSettings.BidProcessingMode)
            {
                return(BadRequest());
            }

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

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

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

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

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

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

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

            EditLeagueYearParameters domainRequest = request.ToDomain(currentUser, eligibilityLevel);
            Result result = await _fantasyCriticService.EditLeague(league.Value, domainRequest);

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

            await _fantasyCriticService.UpdateFantasyPoints(leagueYear.Value);

            return(Ok());
        }