Exemple #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());
        }
        private static MasterGame CreateMasterGame(string guid, string name, string estimatedReleaseDate, LocalDate sortableEstimatedReleaseDate, LocalDate?releaseDate, int?openCriticID, decimal?criticScore,
                                                   LocalDate minimumReleaseDate, int eligibilityLevelID, bool yearlyInstallment, bool earlyAccess, bool freeToPlay, bool releasedInternationally, bool expansionPack,
                                                   string boxartFileName, string firstCriticScoreTimestamp, bool doNotRefreshDate, bool doNotRefreshAnything, string addedTimestamp)
        {
            EligibilityLevel eligibilityLevel = EligibilityLevelFactory.GetEligibilityLevels().Single(x => x.Level == eligibilityLevelID);

            var eligibilitySettings = new EligibilitySettings(eligibilityLevel, false, false, false, false, false, false);

            var game = new MasterGame(Guid.Parse(guid), name, estimatedReleaseDate, sortableEstimatedReleaseDate, releaseDate, openCriticID,
                                      criticScore, minimumReleaseDate, eligibilitySettings, boxartFileName,
                                      InstantPattern.ExtendedIso.Parse(firstCriticScoreTimestamp).GetValueOrThrow(), doNotRefreshDate, doNotRefreshAnything,
                                      InstantPattern.ExtendedIso.Parse(addedTimestamp).GetValueOrThrow());

            return(game);
        }
        public async Task <IActionResult> EditLeagueYearSettings([FromBody] LeagueYearSettingsViewModel 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());
            }

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

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

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

            EligibilityLevel eligibilityLevel = await _fantasyCriticService.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());
        }
        public async Task <IActionResult> CreateMasterGameRequest([FromBody] MasterGameRequestRequest request)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

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

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

            MasterGameRequest domainRequest = request.ToDomain(currentUser, _clock.GetCurrentInstant(), eligibilityLevel);

            await _interLeagueService.CreateMasterGameRequest(domainRequest);

            return(Ok());
        }
        public async Task <IActionResult> CreateMasterGame([FromBody] CreateMasterGameRequest viewModel)
        {
            EligibilityLevel eligibilityLevel = await _interLeagueService.GetEligibilityLevel(viewModel.EligibilityLevel);

            Instant   instant  = _clock.GetCurrentInstant();
            LocalDate tomorrow = instant.ToEasternDate().PlusDays(1);

            var currentYear = await _interLeagueService.GetCurrentYear();

            MasterGame masterGame = viewModel.ToDomain(eligibilityLevel, instant, tomorrow);
            await _interLeagueService.CreateMasterGame(masterGame);

            var vm = new MasterGameViewModel(masterGame, _clock);

            _logger.LogInformation($"Created master game: {masterGame.MasterGameID}");
            return(CreatedAtAction("MasterGame", "Game", new { id = masterGame.MasterGameID }, vm));
        }
 public EditLeagueYearParameters(FantasyCriticUser manager, Guid leagueID, int year, int standardGames, int gamesToDraft, int counterPicks,
                                 EligibilityLevel maximumEligibilityLevel, bool allowYearlyInstallments,
                                 bool allowEarlyAccess, DraftSystem draftSystem, PickupSystem pickupSystem, ScoringSystem scoringSystem)
 {
     Manager                 = manager;
     LeagueID                = leagueID;
     Year                    = year;
     StandardGames           = standardGames;
     GamesToDraft            = gamesToDraft;
     CounterPicks            = counterPicks;
     AllowYearlyInstallments = allowYearlyInstallments;
     AllowEarlyAccess        = allowEarlyAccess;
     MaximumEligibilityLevel = maximumEligibilityLevel;
     DraftSystem             = draftSystem;
     PickupSystem            = pickupSystem;
     ScoringSystem           = scoringSystem;
 }
 public LeagueCreationParameters(FantasyCriticUser manager, string leagueName, int standardGames, int gamesToDraft, int counterPicks,
                                 int initialYear, EligibilityLevel maximumEligibilityLevel, bool allowYearlyInstallments,
                                 bool allowEarlyAccess, DraftSystem draftSystem, PickupSystem pickupSystem, ScoringSystem scoringSystem)
 {
     Manager                 = manager;
     LeagueName              = leagueName;
     StandardGames           = standardGames;
     GamesToDraft            = gamesToDraft;
     CounterPicks            = counterPicks;
     InitialYear             = initialYear;
     AllowYearlyInstallments = allowYearlyInstallments;
     AllowEarlyAccess        = allowEarlyAccess;
     MaximumEligibilityLevel = maximumEligibilityLevel;
     DraftSystem             = draftSystem;
     PickupSystem            = pickupSystem;
     ScoringSystem           = scoringSystem;
 }
Exemple #8
0
        public async Task <Maybe <MasterGameYear> > GetMasterGameYear(Guid masterGameID, int year)
        {
            using (var connection = new MySqlConnection(_connectionString))
            {
                MasterGameYearEntity masterGame = await connection.QuerySingleOrDefaultAsync <MasterGameYearEntity>("select * from vwmastergame where MasterGameID = @masterGameID and Year = @year", new { masterGameID, year });

                if (masterGame == null)
                {
                    return(Maybe <MasterGameYear> .None);
                }

                IEnumerable <MasterSubGameEntity> masterSubGames = await connection.QueryAsync <MasterSubGameEntity>("select * from tblmastersubgame where MasterGameID = @masterGameID", new { masterGameID });

                EligibilityLevel eligibilityLevel = await GetEligibilityLevel(masterGame.EligibilityLevel);

                MasterGameYear domain = masterGame.ToDomain(masterSubGames.Select(x => x.ToDomain()), eligibilityLevel, year);
                return(Maybe <MasterGameYear> .From(domain));
            }
        }
        public MasterGameRequest ToDomain(FantasyCriticUser user, EligibilityLevel eligibilityLevel, Maybe <MasterGame> masterGame)
        {
            Instant requestTimestamp  = LocalDateTime.FromDateTime(RequestTimestamp).InZoneStrictly(DateTimeZone.Utc).ToInstant();
            Instant?responseTimestamp = null;

            if (ResponseTimestamp.HasValue)
            {
                responseTimestamp = LocalDateTime.FromDateTime(ResponseTimestamp.Value).InZoneStrictly(DateTimeZone.Utc).ToInstant();
            }

            LocalDate?releaseDate = null;

            if (ReleaseDate.HasValue)
            {
                releaseDate = LocalDate.FromDateTime(ReleaseDate.Value);
            }

            return(new MasterGameRequest(RequestID, user, requestTimestamp, RequestNote, GameName, SteamID, OpenCriticID, releaseDate, EstimatedReleaseDate, eligibilityLevel,
                                         YearlyInstallment, EarlyAccess, FreeToPlay, ReleasedInternationally, ExpansionPack, UnannouncedGame, Answered, responseTimestamp, ResponseNote, masterGame, Hidden));
        }
        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());
        }
Exemple #11
0
        public async Task <IReadOnlyList <MasterGame> > GetMasterGames()
        {
            using (var connection = new MySqlConnection(_connectionString))
            {
                var masterGameResults = await connection.QueryAsync <MasterGameEntity>("select * from tblmastergame;");

                var masterSubGameResults = await connection.QueryAsync <MasterSubGameEntity>("select * from tblmastersubgame;");

                var masterSubGames            = masterSubGameResults.Select(x => x.ToDomain()).ToList();
                List <MasterGame> masterGames = new List <MasterGame>();
                foreach (var entity in masterGameResults)
                {
                    EligibilityLevel eligibilityLevel = await GetEligibilityLevel(entity.EligibilityLevel);

                    MasterGame domain =
                        entity.ToDomain(masterSubGames.Where(sub => sub.MasterGameID == entity.MasterGameID),
                                        eligibilityLevel);
                    masterGames.Add(domain);
                }

                return(masterGames);
            }
        }
        public EligibilitySettings ToDomain(EligibilityLevel eligibilityLevel)
        {
            var eligibilitySettings = new EligibilitySettings(eligibilityLevel, YearlyInstallment, EarlyAccess, FreeToPlay, ReleasedInternationally, ExpansionPack, UnannouncedGame);

            return(eligibilitySettings);
        }
Exemple #13
0
        public MasterGameRequest ToDomain(FantasyCriticUser user, Instant requestTimestamp, EligibilityLevel eligibilityLevel)
        {
            int?steamID           = null;
            var steamGameIDString = SubstringSearching.GetBetween(SteamLink, "/app/", "/");

            if (steamGameIDString.IsSuccess)
            {
                bool parseResult = int.TryParse(steamGameIDString.Value, out int steamIDResult);
                if (parseResult)
                {
                    steamID = steamIDResult;
                }
            }

            int?openCriticID = URLParsingExtensions.GetOpenCriticIDFromURL(OpenCriticLink);

            return(new MasterGameRequest(Guid.NewGuid(), user, requestTimestamp, RequestNote, GameName, steamID, openCriticID, EstimatedReleaseDate, eligibilityLevel,
                                         YearlyInstallment, EarlyAccess, FreeToPlay, ReleasedInternationally, ExpansionPack, false, null, null, Maybe <Lib.Domain.MasterGame> .None, false));
        }
Exemple #14
0
 public EditLeagueYearParameters(FantasyCriticUser manager, Guid leagueID, int year, int standardGames, int gamesToDraft, int counterPicks,
                                 int freeDroppableGames, int willNotReleaseDroppableGames, int willReleaseDroppableGames, bool dropOnlyDraftGames, EligibilityLevel maximumEligibilityLevel, bool allowYearlyInstallments,
                                 bool allowEarlyAccess, bool allowFreeToPlay, bool allowReleasedInternationally, bool allowExpansions, DraftSystem draftSystem,
                                 PickupSystem pickupSystem, ScoringSystem scoringSystem, bool publicLeague)
 {
     Manager                      = manager;
     LeagueID                     = leagueID;
     Year                         = year;
     StandardGames                = standardGames;
     GamesToDraft                 = gamesToDraft;
     CounterPicks                 = counterPicks;
     FreeDroppableGames           = freeDroppableGames;
     WillNotReleaseDroppableGames = willNotReleaseDroppableGames;
     WillReleaseDroppableGames    = willReleaseDroppableGames;
     DropOnlyDraftGames           = dropOnlyDraftGames;
     AllowedEligibilitySettings   = new EligibilitySettings(maximumEligibilityLevel, allowYearlyInstallments, allowEarlyAccess, allowFreeToPlay,
                                                            allowReleasedInternationally, allowExpansions);
     DraftSystem   = draftSystem;
     PickupSystem  = pickupSystem;
     ScoringSystem = scoringSystem;
     PublicLeague  = publicLeague;
 }
Exemple #15
0
        public MasterGame ToDomain(EligibilityLevel eligibilityLevel)
        {
            MasterGame masterGame = new MasterGame(Guid.NewGuid(), GameName, EstimatedReleaseDate, ReleaseDate, OpenCriticID, null, MinimumReleaseYear, eligibilityLevel, YearlyInstallment, EarlyAccess, BoxartFileName);

            return(masterGame);
        }
Exemple #16
0
        public MasterGame ToDomain(EligibilityLevel eligibilityLevel)
        {
            MasterGame masterGame = new MasterGame(Guid.NewGuid(), GameName, EstimatedReleaseDate, ReleaseDate, null, null, MinimumReleaseYear, eligibilityLevel, false, false, "");

            return(masterGame);
        }
Exemple #17
0
 public LeagueCreationParameters(FantasyCriticUser manager, string leagueName, int standardGames, int gamesToDraft, int counterPicks,
                                 int freeDroppableGames, int willNotReleaseDroppableGames, int willReleaseDroppableGames, bool dropOnlyDraftGames, int initialYear, EligibilityLevel maximumEligibilityLevel,
                                 bool allowYearlyInstallments, bool allowEarlyAccess, bool allowFreeToPlay, bool allowReleasedInternationally,
                                 bool allowExpansions, bool allowUnannouncedGames, DraftSystem draftSystem, PickupSystem pickupSystem, ScoringSystem scoringSystem, bool publicLeague, bool testLeague)
 {
     Manager                      = manager;
     LeagueName                   = leagueName;
     StandardGames                = standardGames;
     GamesToDraft                 = gamesToDraft;
     CounterPicks                 = counterPicks;
     FreeDroppableGames           = freeDroppableGames;
     WillNotReleaseDroppableGames = willNotReleaseDroppableGames;
     WillReleaseDroppableGames    = willReleaseDroppableGames;
     DropOnlyDraftGames           = dropOnlyDraftGames;
     InitialYear                  = initialYear;
     AllowedEligibilitySettings   = new EligibilitySettings(maximumEligibilityLevel, allowYearlyInstallments, allowEarlyAccess,
                                                            allowFreeToPlay, allowReleasedInternationally, allowExpansions, allowUnannouncedGames);
     DraftSystem   = draftSystem;
     PickupSystem  = pickupSystem;
     ScoringSystem = scoringSystem;
     PublicLeague  = publicLeague;
     TestLeague    = testLeague;
 }