public async Task <ClaimResult> ClaimGame(ClaimGameDomainRequest request, bool managerAction, bool draft, bool drafting) { MasterGameYear?masterGameYear = null; if (request.MasterGame is not null) { masterGameYear = new MasterGameYear(request.MasterGame, request.LeagueYear.Year); } ClaimResult claimResult = CanClaimGame(request, null, null, true, drafting); if (!claimResult.Success) { return(claimResult); } PublisherGame playerGame = new PublisherGame(request.Publisher.PublisherID, Guid.NewGuid(), request.GameName, _clock.GetCurrentInstant(), request.CounterPick, null, false, null, masterGameYear, claimResult.BestSlotNumber !.Value, request.DraftPosition, request.OverallDraftPosition, null, null); LeagueAction leagueAction = new LeagueAction(request, _clock.GetCurrentInstant(), managerAction, draft, request.AutoDraft); await _fantasyCriticRepo.AddLeagueAction(leagueAction); await _fantasyCriticRepo.AddPublisherGame(playerGame); return(claimResult); }
public LeagueAction ToDomain(Publisher publisher) { Instant instant = LocalDateTime.FromDateTime(Timestamp).InZoneStrictly(DateTimeZone.Utc).ToInstant(); LeagueAction action = new LeagueAction(publisher, instant, ActionType, Description, ManagerAction); return(action); }
public async Task <ClaimResult> ClaimGame(ClaimGameDomainRequest request, bool managerAction, bool draft, IReadOnlyList <Publisher> publishersForYear) { Maybe <MasterGameYear> masterGameYear = Maybe <MasterGameYear> .None; if (request.MasterGame.HasValue) { masterGameYear = new MasterGameYear(request.MasterGame.Value, request.Publisher.LeagueYear.Year); } PublisherGame playerGame = new PublisherGame(request.Publisher.PublisherID, Guid.NewGuid(), request.GameName, _clock.GetCurrentInstant(), request.CounterPick, null, null, masterGameYear, request.DraftPosition, request.OverallDraftPosition); var supportedYears = await _fantasyCriticRepo.GetSupportedYears(); LeagueYear leagueYear = request.Publisher.LeagueYear; ClaimResult claimResult = CanClaimGame(request, supportedYears, leagueYear, publishersForYear, null, false); if (!claimResult.Success) { return(claimResult); } LeagueAction leagueAction = new LeagueAction(request, _clock.GetCurrentInstant(), managerAction, draft, request.AutoDraft); await _fantasyCriticRepo.AddLeagueAction(leagueAction); await _fantasyCriticRepo.AddPublisherGame(playerGame); return(claimResult); }
private static BidProcessingResults GetProcessingResults(IEnumerable <PickupBid> successBids, IEnumerable <FailedPickupBid> failedBids, IEnumerable <Publisher> publishers, IClock clock) { List <Publisher> updatedPublishers = publishers.ToList(); List <PublisherGame> gamesToAdd = new List <PublisherGame>(); List <LeagueAction> leagueActions = new List <LeagueAction>(); foreach (var successBid in successBids) { PublisherGame newPublisherGame = new PublisherGame(successBid.Publisher.PublisherID, Guid.NewGuid(), successBid.MasterGame.GameName, clock.GetCurrentInstant(), false, null, null, new MasterGameYear(successBid.MasterGame, successBid.Publisher.LeagueYear.Year), null, null); gamesToAdd.Add(newPublisherGame); var affectedPublisher = updatedPublishers.Single(x => x.PublisherID == successBid.Publisher.PublisherID); affectedPublisher.AcquireGame(newPublisherGame, successBid.BidAmount); LeagueAction leagueAction = new LeagueAction(successBid, clock.GetCurrentInstant()); leagueActions.Add(leagueAction); } foreach (var failedBid in failedBids) { LeagueAction leagueAction = new LeagueAction(failedBid, clock.GetCurrentInstant()); leagueActions.Add(leagueAction); } var simpleFailedBids = failedBids.Select(x => x.PickupBid); BidProcessingResults bidProcessingResults = new BidProcessingResults(successBids, simpleFailedBids, leagueActions, updatedPublishers, gamesToAdd); return(bidProcessingResults); }
public async Task SetEligibilityOverride(LeagueYear leagueYear, MasterGame masterGame, bool?eligible) { if (!eligible.HasValue) { await _fantasyCriticRepo.DeleteEligibilityOverride(leagueYear, masterGame); } else { await _fantasyCriticRepo.SetEligibilityOverride(leagueYear, masterGame, eligible.Value); } var allPublishers = await _publisherService.GetPublishersInLeagueForYear(leagueYear); var managerPublisher = allPublishers.Single(x => x.User.UserID == leagueYear.League.LeagueManager.UserID); string description; if (!eligible.HasValue) { description = $"{masterGame.GameName}'s eligibility setting was reset to normal."; } else if (eligible.Value) { description = $"{masterGame.GameName} was manually set to 'Eligible'"; } else { description = $"{masterGame.GameName} was manually set to 'Ineligible'"; } LeagueAction eligibilityAction = new LeagueAction(managerPublisher, _clock.GetCurrentInstant(), "Eligibility Setting Changed", description, true); await _fantasyCriticRepo.AddLeagueAction(eligibilityAction); }
public async Task <Result> RemovePublisherGame(LeagueYear leagueYear, Publisher publisher, PublisherGame publisherGame) { IReadOnlyList <Publisher> allPublishers = await _fantasyCriticRepo.GetPublishersInLeagueForYear(leagueYear); IReadOnlyList <Publisher> publishersForYear = allPublishers.Where(x => x.LeagueYear.Year == leagueYear.Year).ToList(); IReadOnlyList <Publisher> otherPublishers = publishersForYear.Where(x => x.User.UserID != publisher.User.UserID).ToList(); IReadOnlyList <PublisherGame> otherPlayersGames = otherPublishers.SelectMany(x => x.PublisherGames).ToList(); bool otherPlayerHasCounterPick = otherPlayersGames.Where(x => x.CounterPick).ContainsGame(publisherGame); if (otherPlayerHasCounterPick) { return(Result.Failure("Can't remove a publisher game that another player has as a counterPick.")); } var result = await _fantasyCriticRepo.RemovePublisherGame(publisherGame.PublisherGameID); if (result.IsSuccess) { RemoveGameDomainRequest removeGameRequest = new RemoveGameDomainRequest(publisher, publisherGame); LeagueAction leagueAction = new LeagueAction(removeGameRequest, _clock.GetCurrentInstant()); await _fantasyCriticRepo.AddLeagueAction(leagueAction); } return(result); }
public async Task <IReadOnlyList <LeagueAction> > GetLeagueActions(LeagueYear leagueYear) { using (var connection = new MySqlConnection(_connectionString)) { var entities = await connection.QueryAsync <LeagueActionEntity>( "select * from tblleagueaction " + "join tblpublisher on (tblleagueaction.PublisherID = tblpublisher.PublisherID) " + "where tblpublisher.LeagueID = @leagueID and tblpublisher.Year = @leagueYear;", new { leagueID = leagueYear.League.LeagueID, leagueYear = leagueYear.Year }); List <LeagueAction> leagueActions = new List <LeagueAction>(); foreach (var entity in entities) { Publisher publisher = (await GetPublisher(entity.PublisherID)).Value; LeagueAction leagueAction = entity.ToDomain(publisher); leagueActions.Add(leagueAction); } return(leagueActions); } }
public LeagueActionViewModel(LeagueAction leagueAction, IClock clock) { PublisherName = leagueAction.Publisher.PublisherName; Timestamp = leagueAction.Timestamp.ToDateTimeUtc(); ActionType = leagueAction.ActionType; Description = leagueAction.Description; ManagerAction = leagueAction.ManagerAction; }
public LeagueActionEntity(LeagueAction action) { PublisherID = action.Publisher.PublisherID; Timestamp = action.Timestamp.ToDateTimeUtc(); ActionType = action.ActionType; Description = action.Description; ManagerAction = action.ManagerAction; }
public LeagueActionViewModel(LeagueYear leagueYear, LeagueAction leagueAction) { LeagueName = leagueYear.League.LeagueName; PublisherName = leagueAction.Publisher.PublisherName; Timestamp = leagueAction.Timestamp; ActionType = leagueAction.ActionType; Description = leagueAction.Description; ManagerAction = leagueAction.ManagerAction; }
public ComparableLeagueActionViewModel(LeagueAction domain) { LeagueID = domain.Publisher.LeagueYearKey.LeagueID; PublisherID = domain.Publisher.PublisherID; PublisherName = domain.Publisher.PublisherName; ActionType = domain.ActionType; Description = domain.Description; ManagerAction = domain.ManagerAction; }
public async Task <Result> RemovePublisherGame(LeagueYear leagueYear, Publisher publisher, PublisherGame publisherGame) { var now = _clock.GetCurrentInstant(); var formerPublisherGame = publisherGame.GetFormerPublisherGame(now, "Removed by league manager"); RemoveGameDomainRequest removeGameRequest = new RemoveGameDomainRequest(publisher, publisherGame); LeagueAction leagueAction = new LeagueAction(removeGameRequest, now); var result = await _fantasyCriticRepo.ManagerRemovePublisherGame(leagueYear, publisher, publisherGame, formerPublisherGame, leagueAction); return(result); }
public async Task AddLeagueAction(LeagueAction action) { LeagueActionEntity entity = new LeagueActionEntity(action); using (var connection = new MySqlConnection(_connectionString)) { await connection.ExecuteAsync( "insert into tblleagueaction(PublisherID,Timestamp,ActionType,Description,ManagerAction) VALUES " + "(@PublisherID,@Timestamp,@ActionType,@Description,@ManagerAction);", entity); } }
public async Task <ClaimResult> AssociateGame(AssociateGameDomainRequest request) { ClaimResult claimResult = await CanAssociateGame(request); if (!claimResult.Success) { return(claimResult); } LeagueAction leagueAction = new LeagueAction(request, _clock.GetCurrentInstant()); await _fantasyCriticRepo.AddLeagueAction(leagueAction); await _fantasyCriticRepo.AssociatePublisherGame(request.Publisher, request.PublisherGame, request.MasterGame); return(claimResult); }
public DropProcessingResults ProcessDropsIteration(IReadOnlyDictionary <LeagueYear, IReadOnlyList <DropRequest> > allDropRequests, IEnumerable <Publisher> allPublishers, IClock clock, IReadOnlyList <SupportedYear> supportedYears) { List <Publisher> updatedPublishers = allPublishers.ToList(); List <PublisherGame> gamesToDelete = new List <PublisherGame>(); List <LeagueAction> leagueActions = new List <LeagueAction>(); List <DropRequest> successDrops = new List <DropRequest>(); List <DropRequest> failedDrops = new List <DropRequest>(); foreach (var leagueYearGroup in allDropRequests) { foreach (var dropRequest in leagueYearGroup.Value) { var affectedPublisher = updatedPublishers.Single(x => x.PublisherID == dropRequest.Publisher.PublisherID); var publishersInLeague = updatedPublishers.Where(x => x.LeagueYear.Equals(affectedPublisher.LeagueYear)); var otherPublishersInLeague = publishersInLeague.Except(new List <Publisher>() { affectedPublisher }); var dropResult = _gameAcquisitionService.CanDropGame(dropRequest, supportedYears, leagueYearGroup.Key, affectedPublisher, otherPublishersInLeague); if (dropResult.Result.IsSuccess) { successDrops.Add(dropRequest); var publisherGame = dropRequest.Publisher.GetPublisherGame(dropRequest.MasterGame); gamesToDelete.Add(publisherGame.Value); LeagueAction leagueAction = new LeagueAction(dropRequest, dropResult, clock.GetCurrentInstant()); affectedPublisher.DropGame(publisherGame.Value.WillRelease()); leagueActions.Add(leagueAction); } else { failedDrops.Add(dropRequest); LeagueAction leagueAction = new LeagueAction(dropRequest, dropResult, clock.GetCurrentInstant()); leagueActions.Add(leagueAction); } } } DropProcessingResults dropProcessingResults = new DropProcessingResults(successDrops, failedDrops, leagueActions, updatedPublishers, gamesToDelete); return(dropProcessingResults); }
public async Task <ClaimResult> ClaimGame(ClaimGameDomainRequest request) { PublisherGame playerGame = new PublisherGame(Guid.NewGuid(), request.GameName, _clock.GetCurrentInstant(), request.CounterPick, null, null, new MasterGameYear(request.MasterGame.Value, request.Publisher.Year), request.DraftPosition, request.OverallDraftPosition, request.Publisher.Year); ClaimResult claimResult = await CanClaimGame(request); if (!claimResult.Success) { return(claimResult); } LeagueAction leagueAction = new LeagueAction(request, _clock.GetCurrentInstant()); await _fantasyCriticRepo.AddLeagueAction(leagueAction); await _fantasyCriticRepo.AddPublisherGame(request.Publisher, playerGame); return(claimResult); }
public async Task <Result> EditPublisher(EditPublisherRequest editValues) { if (!editValues.SomethingChanged()) { return(Result.Failure("You need to specify something to change.")); } if (editValues.Budget.HasValue && editValues.Budget.Value > 100) { return(Result.Failure("Budget cannot be set to over $100.")); } if (editValues.Budget.HasValue && editValues.Budget.Value < 0) { return(Result.Failure("Budget cannot be set to under $0.")); } if (editValues.WillReleaseGamesDropped.HasValue && editValues.WillReleaseGamesDropped.Value > editValues.Publisher.LeagueYear.Options.WillReleaseDroppableGames) { return(Result.Failure("Will release games dropped cannot be set to more than is allowed in the league.")); } if (editValues.WillNotReleaseGamesDropped.HasValue && editValues.WillNotReleaseGamesDropped.Value > editValues.Publisher.LeagueYear.Options.WillNotReleaseDroppableGames) { return(Result.Failure("Will not release games dropped cannot be set to more than is allowed in the league.")); } if (editValues.FreeGamesDropped.HasValue && editValues.FreeGamesDropped.Value > editValues.Publisher.LeagueYear.Options.FreeDroppableGames) { return(Result.Failure("Unrestricted games dropped cannot be set to more than is allowed in the league.")); } LeagueAction leagueAction = new LeagueAction(editValues, _clock.GetCurrentInstant()); await _fantasyCriticRepo.EditPublisher(editValues, leagueAction); return(Result.Success()); }
private static LeagueAction GetActionForPublisher(Publisher publisher, Instant actionTime, IEnumerable <MasterGameYearWithCounterPick> games, uint budgetSend) { List <string> acquisitions = new List <string>(); foreach (var game in games) { var counterPickString = ""; if (game.CounterPick) { counterPickString = " (Counter Pick)"; } acquisitions.Add($"Acquired '{game.MasterGameYear.MasterGame.GameName}'{counterPickString}."); } if (budgetSend > 0) { acquisitions.Add($"Acquired ${budgetSend} of budget."); } string finalString = string.Join("\n", acquisitions.Select(x => $"• {x}")); var proposerAction = new LeagueAction(publisher, actionTime, "Trade Executed", finalString, true); return(proposerAction); }
private ActionProcessingResults ProcessDrops(IReadOnlyDictionary <LeagueYear, IReadOnlyList <DropRequest> > allDropRequests, PublisherStateSet publisherStateSet, Instant processingTime) { List <FormerPublisherGame> gamesToDelete = new List <FormerPublisherGame>(); List <LeagueAction> leagueActions = new List <LeagueAction>(); List <DropRequest> successDrops = new List <DropRequest>(); List <DropRequest> failedDrops = new List <DropRequest>(); foreach (var leagueYearGroup in allDropRequests) { foreach (var dropRequest in leagueYearGroup.Value) { var affectedPublisher = publisherStateSet.GetPublisher(dropRequest.Publisher.PublisherID); var dropResult = _gameAcquisitionService.CanDropGame(dropRequest, leagueYearGroup.Key, affectedPublisher); if (dropResult.Result.IsSuccess) { successDrops.Add(dropRequest); var publisherGame = dropRequest.Publisher.GetPublisherGameOrThrow(dropRequest.MasterGame); var formerPublisherGame = publisherGame.GetFormerPublisherGame(processingTime, "Dropped by player"); gamesToDelete.Add(formerPublisherGame); LeagueAction leagueAction = new LeagueAction(dropRequest, dropResult, processingTime); publisherStateSet.DropGameForPublisher(affectedPublisher, publisherGame, leagueYearGroup.Key.Options); leagueActions.Add(leagueAction); } else { failedDrops.Add(dropRequest); LeagueAction leagueAction = new LeagueAction(dropRequest, dropResult, processingTime); leagueActions.Add(leagueAction); } } } ActionProcessingResults dropProcessingResults = ActionProcessingResults.GetResultsSetFromDropResults(successDrops, failedDrops, leagueActions, publisherStateSet, gamesToDelete); return(dropProcessingResults); }
private async Task ProcessSuccessfulAndFailedBids(IEnumerable <PickupBid> successBids, IEnumerable <FailedPickupBid> failedBids) { foreach (var successBid in successBids) { await _fantasyCriticRepo.MarkBidStatus(successBid, true); PublisherGame newPublisherGame = new PublisherGame(Guid.NewGuid(), successBid.MasterGame.GameName, _clock.GetCurrentInstant(), false, null, null, new MasterGameYear(successBid.MasterGame, successBid.Publisher.Year), null, null, successBid.Publisher.Year); await _fantasyCriticRepo.AddPublisherGame(successBid.Publisher, newPublisherGame); await _fantasyCriticRepo.SpendBudget(successBid.Publisher, successBid.BidAmount); LeagueAction leagueAction = new LeagueAction(successBid, _clock.GetCurrentInstant()); await _fantasyCriticRepo.AddLeagueAction(leagueAction); } foreach (var failedBid in failedBids) { await _fantasyCriticRepo.MarkBidStatus(failedBid.PickupBid, false); LeagueAction leagueAction = new LeagueAction(failedBid, _clock.GetCurrentInstant()); await _fantasyCriticRepo.AddLeagueAction(leagueAction); } }
public async Task <Result> EditLeague(LeagueYear leagueYear, LeagueYearParameters parameters) { if (leagueYear.SupportedYear.Finished) { return(Result.Failure("You cannot edit a completed year.")); } var league = leagueYear.League; LeagueOptions options = new LeagueOptions(parameters); var validateOptions = options.Validate(); if (validateOptions.IsFailure) { return(Result.Failure(validateOptions.Error)); } if (parameters.ScoringSystem.Name != DiminishingScoringSystem.StaticName) { return(Result.Failure("That scoring mode is no longer supported.")); } IReadOnlyList <Publisher> publishers = leagueYear.Publishers; int maxStandardGames = publishers.Select(publisher => publisher.PublisherGames.Count(x => !x.CounterPick)).DefaultIfEmpty(0).Max(); int maxCounterPicks = publishers.Select(publisher => publisher.PublisherGames.Count(x => x.CounterPick)).DefaultIfEmpty(0).Max(); if (maxStandardGames > options.StandardGames) { return(Result.Failure($"Cannot reduce number of standard games to {options.StandardGames} as a publisher has {maxStandardGames} standard games currently.")); } if (maxCounterPicks > options.CounterPicks) { return(Result.Failure($"Cannot reduce number of counter picks to {options.CounterPicks} as a publisher has {maxCounterPicks} counter picks currently.")); } if (leagueYear.PlayStatus.DraftIsActive) { if (leagueYear.Options.GamesToDraft > parameters.GamesToDraft) { return(Result.Failure("Cannot decrease the number of drafted games during the draft. Reset the draft if you need to do this.")); } if (leagueYear.Options.CounterPicksToDraft > parameters.CounterPicksToDraft) { return(Result.Failure("Cannot decrease the number of drafted counter picks during the draft. Reset the draft if you need to do this.")); } } if (leagueYear.PlayStatus.DraftFinished) { if (leagueYear.Options.GamesToDraft != parameters.GamesToDraft) { return(Result.Failure("Cannot change the number of drafted games after the draft.")); } if (leagueYear.Options.CounterPicksToDraft != parameters.CounterPicksToDraft) { return(Result.Failure("Cannot change the number of drafted counter picks after the draft.")); } } int maxFreeGamesFreeDropped = publishers.Select(publisher => publisher.FreeGamesDropped).DefaultIfEmpty(0).Max(); int maxWillNotReleaseGamesDropped = publishers.Select(publisher => publisher.WillNotReleaseGamesDropped).DefaultIfEmpty(0).Max(); int maxWillReleaseGamesDropped = publishers.Select(publisher => publisher.WillReleaseGamesDropped).DefaultIfEmpty(0).Max(); if (maxFreeGamesFreeDropped > options.FreeDroppableGames && options.FreeDroppableGames != -1) { return(Result.Failure($"Cannot reduce number of unrestricted droppable games to {options.FreeDroppableGames} as a publisher has already dropped {maxFreeGamesFreeDropped} games.")); } if (maxWillNotReleaseGamesDropped > options.WillNotReleaseDroppableGames && options.WillNotReleaseDroppableGames != -1) { return(Result.Failure($"Cannot reduce number of 'will not release' droppable games to {options.WillNotReleaseDroppableGames} as a publisher has already dropped {maxWillNotReleaseGamesDropped} games.")); } if (maxWillReleaseGamesDropped > options.WillReleaseDroppableGames && options.WillReleaseDroppableGames != -1) { return(Result.Failure($"Cannot reduce number of 'will release' droppable games to {options.WillReleaseDroppableGames} as a publisher has already dropped {maxWillReleaseGamesDropped} games.")); } var slotAssignments = GetNewSlotAssignments(parameters, leagueYear, publishers); var eligibilityOverrides = await GetEligibilityOverrides(league, parameters.Year); var tagOverrides = await GetTagOverrides(league, parameters.Year); var supportedYear = await _interLeagueService.GetSupportedYear(parameters.Year); LeagueYear newLeagueYear = new LeagueYear(league, supportedYear, options, leagueYear.PlayStatus, eligibilityOverrides, tagOverrides, leagueYear.DraftStartedTimestamp, leagueYear.WinningUser, publishers); var managerPublisher = leagueYear.GetManagerPublisherOrThrow(); var differenceString = options.GetDifferenceString(leagueYear.Options); if (differenceString is not null) { LeagueAction settingsChangeAction = new LeagueAction(managerPublisher, _clock.GetCurrentInstant(), "League Year Settings Changed", differenceString, true); await _fantasyCriticRepo.EditLeagueYear(newLeagueYear, slotAssignments, settingsChangeAction); } return(Result.Success()); }
public Task AddLeagueAction(LeagueAction action) { throw new NotImplementedException(); }
public LeagueAction ToDomain(Publisher publisher) { LeagueAction action = new LeagueAction(publisher, Timestamp, ActionType, Description, ManagerAction); return(action); }
public Task EditPublisher(EditPublisherRequest editValues, LeagueAction leagueAction) { throw new NotImplementedException(); }