Exemplo n.º 1
0
        public async Task <IActionResult> GetLeagueYearOptions(Guid leagueID, int year)
        {
            Maybe <League> league = await _fantasyCriticService.GetLeagueByID(leagueID);

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

            Maybe <LeagueYear> leagueYear = await _fantasyCriticService.GetLeagueYear(leagueID, year);

            if (leagueYear.HasNoValue)
            {
                throw new Exception("Something went really wrong, no options are set up for this league.");
            }

            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            var usersInLeague = await _fantasyCriticService.GetUsersInLeague(leagueYear.Value.League);

            bool userIsInLeague = usersInLeague.Any(x => x.UserID == currentUser.UserID);

            if (!userIsInLeague)
            {
                return(Unauthorized());
            }

            var leagueViewModel = new LeagueYearSettingsViewModel(league.Value, leagueYear.Value);

            return(Ok(leagueViewModel));
        }
Exemplo n.º 2
0
 public CreateLeagueRequest(string leagueName, bool publicLeague, bool testLeague, LeagueYearSettingsViewModel leagueYearSettings)
 {
     LeagueName         = leagueName;
     PublicLeague       = publicLeague;
     TestLeague         = testLeague;
     LeagueYearSettings = leagueYearSettings;
 }
    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());
    }
Exemplo n.º 4
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());
        }