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 LeagueAction(RemoveGameDomainRequest action, Instant timestamp) { Timestamp = timestamp; Publisher = action.Publisher; ActionType = "Publisher Game Removed"; Description = $"Removed game: '{action.PublisherGame.GameName}'"; ManagerAction = true; }
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); }