public async Task <IActionResult> ManagerAssociateGame([FromBody] AssociateGameRequest request) { var leagueYearPublisherGameRecord = await GetExistingLeagueYearAndPublisherGame(request.PublisherID, request.PublisherGameID, ActionProcessingModeBehavior.Ban, RequiredRelationship.LeagueManager, RequiredYearStatus.YearNotFinishedDraftFinished); if (leagueYearPublisherGameRecord.FailedResult is not null) { return(leagueYearPublisherGameRecord.FailedResult); } var validResult = leagueYearPublisherGameRecord.ValidResult !; var leagueYear = validResult.LeagueYear; var publisher = validResult.Publisher; var publisherGame = validResult.PublisherGame; MasterGame?masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID); if (masterGame is null) { return(BadRequest()); } AssociateGameDomainRequest domainRequest = new AssociateGameDomainRequest(leagueYear, publisher, publisherGame, masterGame, request.ManagerOverride); ClaimResult result = await _gameAcquisitionService.AssociateGame(domainRequest); var viewModel = new ManagerClaimResultViewModel(result); await _fantasyCriticService.UpdatePublisherGameCalculatedStats(leagueYear); return(Ok(viewModel)); }
public async Task <IActionResult> ManagerClaimGame([FromBody] ClaimGameRequest request) { var leagueYearPublisherRecord = await GetExistingLeagueYearAndPublisher(request.PublisherID, ActionProcessingModeBehavior.Ban, RequiredRelationship.LeagueManager, RequiredYearStatus.YearNotFinishedDraftFinished); if (leagueYearPublisherRecord.FailedResult is not null) { return(leagueYearPublisherRecord.FailedResult); } var validResult = leagueYearPublisherRecord.ValidResult !; var leagueYear = validResult.LeagueYear; var publisher = validResult.Publisher; MasterGame?masterGame = null; if (request.MasterGameID.HasValue) { masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID.Value); } bool counterPickedGameIsManualWillNotRelease = PlayerGameExtensions.CounterPickedGameIsManualWillNotRelease(leagueYear, request.CounterPick, masterGame, false); ClaimGameDomainRequest domainRequest = new ClaimGameDomainRequest(leagueYear, publisher, request.GameName, request.CounterPick, counterPickedGameIsManualWillNotRelease, request.ManagerOverride, false, masterGame, null, null); ClaimResult result = await _gameAcquisitionService.ClaimGame(domainRequest, true, false, false); var viewModel = new ManagerClaimResultViewModel(result); await _fantasyCriticService.UpdatePublisherGameCalculatedStats(leagueYear); return(Ok(viewModel)); }
public async Task <IActionResult> CompleteMasterGameRequest([FromBody] CompleteMasterGameRequestRequest request) { MasterGameRequest?maybeRequest = await _interLeagueService.GetMasterGameRequest(request.RequestID); if (maybeRequest is null) { return(BadRequest("That request does not exist.")); } MasterGame?masterGame = null; if (request.MasterGameID.HasValue) { masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID.Value); if (masterGame is null) { return(BadRequest("Bad master game")); } } Instant instant = _clock.GetCurrentInstant(); await _interLeagueService.CompleteMasterGameRequest(maybeRequest, instant, request.ResponseNote, masterGame); return(Ok()); }
public bool Equals(MasterGame?other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(MasterGameID.Equals(other.MasterGameID)); }
public async Task <IActionResult> LinkGameToGG([FromBody] LinkGameToGGRequest request) { MasterGame?masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID); if (masterGame is null) { return(BadRequest("Bad master game")); } await _adminService.LinkToGG(masterGame, request.GGToken); return(Ok()); }
public async Task <IActionResult> SetGameTagOverride([FromBody] TagOverrideRequest 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 leagueYear = validResult.LeagueYear; MasterGame?masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID); if (masterGame is null) { return(BadRequest()); } if (masterGame.ReleaseDate.HasValue && masterGame.ReleaseDate.Value.Year < leagueYear.Year) { return(BadRequest("You can't override the tags of a game that came out in a previous year.")); } IReadOnlyList <MasterGameTag> currentOverrideTags = await _fantasyCriticService.GetTagOverridesForGame(leagueYear.League, leagueYear.Year, masterGame); var allTags = await _interLeagueService.GetMasterGameTags(); var requestedTags = allTags.Where(x => request.Tags.Contains(x.Name)).ToList(); if (ListExtensions.SequencesContainSameElements(masterGame.Tags, requestedTags)) { return(BadRequest("That game already has those exact tags.")); } if (ListExtensions.SequencesContainSameElements(currentOverrideTags, requestedTags)) { return(BadRequest("That game is already overriden to have those exact tags.")); } await _fantasyCriticService.SetTagOverride(leagueYear, masterGame, requestedTags); var refreshedLeagueYear = await _fantasyCriticService.GetLeagueYear(leagueYear.League.LeagueID, request.Year); if (refreshedLeagueYear is null) { return(BadRequest()); } await _fantasyCriticService.UpdatePublisherGameCalculatedStats(refreshedLeagueYear); return(Ok()); }
public async Task <IActionResult> SetGameEligibilityOverride([FromBody] EligibilityOverrideRequest 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 leagueYear = validResult.LeagueYear; MasterGame?masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID); if (masterGame is null) { return(BadRequest()); } if (masterGame.ReleaseDate.HasValue && masterGame.ReleaseDate.Value.Year < leagueYear.Year) { return(BadRequest("You can't change the override setting of a game that came out in a previous year.")); } var currentDate = _clock.GetToday(); var eligibilityFactors = leagueYear.GetEligibilityFactorsForMasterGame(masterGame, currentDate); bool alreadyEligible = SlotEligibilityService.GameIsEligibleInLeagueYear(eligibilityFactors); bool isAllowing = request.Eligible.HasValue && request.Eligible.Value; bool isBanning = request.Eligible.HasValue && !request.Eligible.Value; if (isAllowing && alreadyEligible) { return(BadRequest("That game is already eligible in your league.")); } if (isBanning && !alreadyEligible) { return(BadRequest("That game is already ineligible in your league.")); } await _fantasyCriticService.SetEligibilityOverride(leagueYear, masterGame, request.Eligible); var refreshedLeagueYear = await _fantasyCriticService.GetLeagueYear(leagueYear.League.LeagueID, request.Year); if (refreshedLeagueYear is null) { return(BadRequest()); } await _fantasyCriticService.UpdatePublisherGameCalculatedStats(refreshedLeagueYear); return(Ok()); }
public ClaimGameDomainRequest(LeagueYear leagueYear, Publisher publisher, string gameName, bool counterPick, bool counterPickedGameIsManualWillNotRelease, bool managerOverride, bool autoDraft, MasterGame?masterGame, int?draftPosition, int?overallDraftPosition) { LeagueYear = leagueYear; Publisher = publisher; GameName = gameName; CounterPick = counterPick; CounterPickedGameIsManualWillNotRelease = counterPickedGameIsManualWillNotRelease; ManagerOverride = managerOverride; AutoDraft = autoDraft; MasterGame = masterGame; DraftPosition = draftPosition; OverallDraftPosition = overallDraftPosition; }
public async Task <IActionResult> MergeMasterGame([FromBody] MergeGameRequest request) { MasterGame?removeMasterGame = await _interLeagueService.GetMasterGame(request.RemoveMasterGameID); MasterGame?mergeIntoMasterGame = await _interLeagueService.GetMasterGame(request.MergeIntoMasterGameID); if (removeMasterGame is null || mergeIntoMasterGame is null) { return(BadRequest("Bad master game")); } await _adminService.MergeMasterGame(removeMasterGame, mergeIntoMasterGame); return(Ok()); }
public MasterGameRequest(Guid requestID, FantasyCriticUser user, Instant requestTimestamp, string requestNote, string gameName, int?steamID, int?openCriticID, string?ggToken, LocalDate?releaseDate, string estimatedReleaseDate, bool answered, Instant?responseTimestamp, string?responseNote, MasterGame?masterGame, bool hidden) { RequestID = requestID; User = user; RequestTimestamp = requestTimestamp; RequestNote = requestNote; GameName = gameName; SteamID = steamID; OpenCriticID = openCriticID; GGToken = ggToken; ReleaseDate = releaseDate; EstimatedReleaseDate = estimatedReleaseDate; Answered = answered; ResponseTimestamp = responseTimestamp; ResponseNote = responseNote; MasterGame = masterGame; Hidden = hidden; }
private async Task <IReadOnlyList <MasterGameRequest> > ConvertMasterGameRequestEntities(IEnumerable <MasterGameRequestEntity> entities) { var masterGames = await GetMasterGames(); var users = await _userStore.GetAllUsers(); List <MasterGameRequest> domainRequests = new List <MasterGameRequest>(); foreach (var entity in entities) { MasterGame?masterGame = null; if (entity.MasterGameID.HasValue) { masterGame = masterGames.Single(x => x.MasterGameID == entity.MasterGameID.Value); } MasterGameRequest domain = entity.ToDomain(users.Single(x => x.Id == entity.UserID), masterGame); domainRequests.Add(domain); } return(domainRequests); }
public async Task <IActionResult> CreateMasterGameChangeRequest([FromBody] MasterGameChangeRequestRequest request) { var currentUserResult = await GetCurrentUser(); if (currentUserResult.IsFailure) { return(BadRequest(currentUserResult.Error)); } var currentUser = currentUserResult.Value; MasterGame?masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID); if (masterGame is null) { return(NotFound()); } MasterGameChangeRequest domainRequest = request.ToDomain(currentUser, _clock.GetCurrentInstant(), masterGame); await _interLeagueService.CreateMasterGameChangeRequest(domainRequest); return(Ok()); }
public async Task <MasterGameRequest?> GetMasterGameRequest(Guid requestID) { var sql = "select * from tbl_mastergame_request where RequestID = @requestID"; await using var connection = new MySqlConnection(_connectionString); MasterGameRequestEntity entity = await connection.QuerySingleOrDefaultAsync <MasterGameRequestEntity>(sql, new { requestID }); if (entity == null) { return(null); } MasterGame?masterGame = null; if (entity.MasterGameID.HasValue) { masterGame = await GetMasterGame(entity.MasterGameID.Value); } var user = await _userStore.FindByIdAsync(entity.UserID.ToString(), CancellationToken.None); return(entity.ToDomain(user, masterGame)); }
public static bool CounterPickedGameIsManualWillNotRelease(LeagueYear leagueYear, bool counterPick, MasterGame?masterGame, bool gameCouldBeDropped) { if (!counterPick || masterGame is null) { return(false); } var gameBeingCounterPickedOptions = leagueYear.Publishers.Select(x => x.GetPublisherGame(masterGame)) .Where(x => x is not null && !x.CounterPick).Select(x => x !).ToList(); if (gameBeingCounterPickedOptions.Count != 1) { if (gameCouldBeDropped && gameBeingCounterPickedOptions.Count == 0) { return(false); } throw new Exception($"Something very strange has happened with bid processing for league year: {leagueYear.Key}"); } return(gameBeingCounterPickedOptions.Single().ManualWillNotRelease); }
public Task CompleteMasterGameRequest(MasterGameRequest masterGameRequest, Instant responseTime, string responseNote, MasterGame?masterGame) { throw new NotImplementedException(); }
public async Task <IActionResult> ManagerDraftGame([FromBody] ManagerDraftGameRequest request) { var leagueYearPublisherRecord = await GetExistingLeagueYearAndPublisher(request.PublisherID, ActionProcessingModeBehavior.Allow, RequiredRelationship.LeagueManager, RequiredYearStatus.ActiveDraft); if (leagueYearPublisherRecord.FailedResult is not null) { return(leagueYearPublisherRecord.FailedResult); } var validResult = leagueYearPublisherRecord.ValidResult !; var leagueYear = validResult.LeagueYear; var publisher = validResult.Publisher; var nextPublisher = _draftService.GetNextDraftPublisher(leagueYear); if (nextPublisher is null) { return(BadRequest("There are no spots open to draft.")); } if (!nextPublisher.Equals(publisher)) { return(BadRequest("That publisher is not next up for drafting.")); } MasterGame?masterGame = null; if (request.MasterGameID.HasValue) { masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID.Value); } var draftPhase = _draftService.GetDraftPhase(leagueYear); if (draftPhase.Equals(DraftPhase.StandardGames)) { if (request.CounterPick) { return(BadRequest("Not drafting counterPicks now.")); } } if (draftPhase.Equals(DraftPhase.CounterPicks)) { if (!request.CounterPick) { return(BadRequest("Not drafting standard games now.")); } } var draftStatus = _draftService.GetDraftStatus(draftPhase, leagueYear); bool counterPickedGameIsManualWillNotRelease = PlayerGameExtensions.CounterPickedGameIsManualWillNotRelease(leagueYear, request.CounterPick, masterGame, false); ClaimGameDomainRequest domainRequest = new ClaimGameDomainRequest(leagueYear, publisher, request.GameName, request.CounterPick, counterPickedGameIsManualWillNotRelease, request.ManagerOverride, false, masterGame, draftStatus.DraftPosition, draftStatus.OverallDraftPosition); var result = await _draftService.DraftGame(domainRequest, true); var viewModel = new ManagerClaimResultViewModel(result.Result); await _hubContext.Clients.Group(leagueYear.GetGroupName).SendAsync("RefreshLeagueYear"); if (result.DraftComplete) { await _hubContext.Clients.Group(leagueYear.GetGroupName).SendAsync("DraftFinished"); } return(Ok(viewModel)); }
public MasterGameRequest ToDomain(FantasyCriticUser user, MasterGame?masterGame) { return(new MasterGameRequest(RequestID, user, RequestTimestamp, RequestNote, GameName, SteamID, OpenCriticID, GGToken, ReleaseDate, EstimatedReleaseDate, Answered, ResponseTimestamp, ResponseNote, masterGame, Hidden)); }
public Task CompleteMasterGameRequest(MasterGameRequest masterGameRequest, Instant responseTime, string responseNote, MasterGame?masterGame) { return(_masterGameRepo.CompleteMasterGameRequest(masterGameRequest, responseTime, responseNote, masterGame)); }
public async Task CompleteMasterGameRequest(MasterGameRequest masterGameRequest, Instant responseTime, string responseNote, MasterGame?masterGame) { Guid?masterGameID = null; if (masterGame is not null) { masterGameID = masterGame.MasterGameID; } string sql = "update tbl_mastergame_request set Answered = 1, ResponseTimestamp = @responseTime, " + "ResponseNote = @responseNote, MasterGameID = @masterGameID where RequestID = @requestID;"; await using var connection = new MySqlConnection(_connectionString); await connection.ExecuteAsync(sql, new { requestID = masterGameRequest.RequestID, masterGameID, responseTime = responseTime.ToDateTimeUtc(), responseNote }); }