public LeagueCreationParameters ToDomain(FantasyCriticUser manager, IReadOnlyDictionary <string, MasterGameTag> tagDictionary) { LeagueYearParameters leagueYearParameters = LeagueYearSettings.ToDomain(tagDictionary); LeagueCreationParameters parameters = new LeagueCreationParameters(manager, LeagueName, PublicLeague, TestLeague, leagueYearParameters); return(parameters); }
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()); }
public LeagueCreationParameters(FantasyCriticUser manager, string leagueName, bool publicLeague, bool testLeague, LeagueYearParameters leagueYearParameters) { Manager = manager; LeagueName = leagueName; PublicLeague = publicLeague; TestLeague = testLeague; LeagueYearParameters = leagueYearParameters; }
private static IReadOnlyDictionary <Guid, int> GetNewSlotAssignments(LeagueYearParameters parameters, LeagueYear leagueYear, IReadOnlyList <Publisher> publishers) { var slotCountShift = parameters.StandardGames - leagueYear.Options.StandardGames; Dictionary <Guid, int> finalSlotAssignments = new Dictionary <Guid, int>(); if (slotCountShift == 0) { return(finalSlotAssignments); } foreach (var publisher in publishers) { Dictionary <Guid, int> slotAssignmentsForPublisher = new Dictionary <Guid, int>(); var slots = publisher.GetPublisherSlots(leagueYear.Options); var filledNonCounterPickSlots = slots.Where(x => !x.CounterPick && x.PublisherGame is not null).ToList(); int normalSlotNumber = 0; var normalSlots = filledNonCounterPickSlots.Where(x => x.SpecialGameSlot is null); foreach (var normalSlot in normalSlots) { slotAssignmentsForPublisher[normalSlot.PublisherGame !.PublisherGameID] = normalSlotNumber;
public LeagueYearParameters ToDomain(IReadOnlyDictionary <string, MasterGameTag> tagDictionary) { DraftSystem draftSystem = Lib.Enums.DraftSystem.FromValue(DraftSystem); PickupSystem pickupSystem = Lib.Enums.PickupSystem.FromValue(PickupSystem); TradingSystem tradingSystem = Lib.Enums.TradingSystem.FromValue(TradingSystem); TiebreakSystem tiebreakSystem = Lib.Enums.TiebreakSystem.FromValue(TiebreakSystem); ScoringSystem scoringSystem = Lib.Domain.ScoringSystems.ScoringSystem.GetScoringSystem(ScoringSystem); int freeDroppableGames = FreeDroppableGames; if (UnlimitedFreeDroppableGames) { freeDroppableGames = -1; } int willNotReleaseDroppableGames = WillNotReleaseDroppableGames; if (UnlimitedWillNotReleaseDroppableGames) { willNotReleaseDroppableGames = -1; } int willReleaseDroppableGames = WillReleaseDroppableGames; if (UnlimitedWillReleaseDroppableGames) { willReleaseDroppableGames = -1; } var counterPickDeadline = new AnnualDate(CounterPickDeadline.Month, CounterPickDeadline.Day); var leagueTags = Tags.ToDomain(tagDictionary); var specialGameSlots = SpecialGameSlots.Select(x => x.ToDomain(tagDictionary)); LeagueYearParameters parameters = new LeagueYearParameters(LeagueID, Year, StandardGames, GamesToDraft, CounterPicks, CounterPicksToDraft, freeDroppableGames, willNotReleaseDroppableGames, willReleaseDroppableGames, DropOnlyDraftGames, CounterPicksBlockDrops, MinimumBidAmount, leagueTags, specialGameSlots, draftSystem, pickupSystem, scoringSystem, tradingSystem, tiebreakSystem, counterPickDeadline); return(parameters); }
public LeagueOptions(LeagueYearParameters parameters) { StandardGames = parameters.StandardGames; GamesToDraft = parameters.GamesToDraft; CounterPicks = parameters.CounterPicks; CounterPicksToDraft = parameters.CounterPicksToDraft; FreeDroppableGames = parameters.FreeDroppableGames; WillNotReleaseDroppableGames = parameters.WillNotReleaseDroppableGames; WillReleaseDroppableGames = parameters.WillReleaseDroppableGames; DropOnlyDraftGames = parameters.DropOnlyDraftGames; CounterPicksBlockDrops = parameters.CounterPicksBlockDrops; MinimumBidAmount = parameters.MinimumBidAmount; LeagueTags = parameters.LeagueTags; SpecialGameSlots = parameters.SpecialGameSlots.OrderBy(x => x.SpecialSlotPosition).ToList(); DraftSystem = parameters.DraftSystem; PickupSystem = parameters.PickupSystem; ScoringSystem = parameters.ScoringSystem; TradingSystem = parameters.TradingSystem; TiebreakSystem = parameters.TiebreakSystem; CounterPickDeadline = parameters.CounterPickDeadline; _specialSlotDictionary = SpecialGameSlots.ToDictionary(specialGameSlot => StandardGames - SpecialGameSlots.Count + specialGameSlot.SpecialSlotPosition); }
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()); }