From 555201e97e91066fbec06b787bcc5fd0b1ecf98b Mon Sep 17 00:00:00 2001 From: axunonb Date: Mon, 7 Oct 2024 13:15:55 +0200 Subject: [PATCH] Optimize collection access * Replace `First()` and `FirstOrDefault()` with index-based access (`[0]`) or `Find()` to enhance readability and performance. * Change `Any()` to `Exists()` and `All()` to `TrueForAll()` for consistency and potential performance gains. * Update lambda expressions to use pattern matching for null and property checks. * Modify string comparisons to use single quotes for characters. * Replace `Last()` with index-based access (`[^1]`). --- .../ViewComponents/CustomMainNavigationNodeBuilder.cs | 2 +- League/BackgroundTasks/RankingUpdateTask.cs | 2 +- .../Components/MainNavigationComponentModelExtensions.cs | 4 ++-- League/Controllers/Language.cs | 2 +- League/Controllers/Match.cs | 2 +- League/Controllers/Ranking.cs | 4 ++-- League/Controllers/TeamApplication.cs | 8 ++++---- League/Emailing/Creators/ChangeFixtureCreator.cs | 4 ++-- League/Emailing/Creators/ConfirmTeamApplicationCreator.cs | 2 +- League/Emailing/Creators/ResultEnteredCreator.cs | 4 ++-- League/LeagueStartup.cs | 2 +- League/Models/MapViewModels/MapModel.cs | 2 +- League/Models/RankingViewModels/AllTimeTeamModel.cs | 2 +- League/Models/TeamViewModels/TeamEditModel.cs | 2 +- League/TagHelpers/Modal/SiteModalToggleTagHelper.cs | 2 +- League/Views/Map/Index.cshtml | 4 ++-- League/Views/Match/Fixtures.cshtml | 2 +- League/Views/Match/Results.cshtml | 4 ++-- League/Views/Ranking/Table.cshtml | 2 +- League/Views/Team/MyTeam.cshtml | 2 +- .../DAL/DatabaseGeneric/CustomExtensions/UserEntity.cs | 4 ++-- .../CustomExtensions/QueryCreationManagerExt.cs | 4 ++-- .../TournamentManager/Data/TeamRespository.cs | 2 +- .../TournamentManager/ModelValidators/FixtureValidator.cs | 8 ++++---- .../TournamentManager/ModelValidators/SetsValidator.cs | 2 +- .../TournamentManager/ModelValidators/VenueValidator.cs | 2 +- .../TournamentManager/Plan/MatchScheduler.cs | 2 +- .../TournamentManager/Ranking/RankingChart.cs | 2 +- 28 files changed, 42 insertions(+), 42 deletions(-) diff --git a/League.Demo/ViewComponents/CustomMainNavigationNodeBuilder.cs b/League.Demo/ViewComponents/CustomMainNavigationNodeBuilder.cs index dbc2225b..191cc9d8 100644 --- a/League.Demo/ViewComponents/CustomMainNavigationNodeBuilder.cs +++ b/League.Demo/ViewComponents/CustomMainNavigationNodeBuilder.cs @@ -76,7 +76,7 @@ protected override async Task CreateStandardNavigationNodes() InsertTopNavigationNode(info, "Top_Teams"); } - InsertTopNavigationNode(home, NavigationNodes.First().Key); + InsertTopNavigationNode(home, NavigationNodes[0].Key); #endregion } diff --git a/League/BackgroundTasks/RankingUpdateTask.cs b/League/BackgroundTasks/RankingUpdateTask.cs index 0c5085e9..2fb69840 100644 --- a/League/BackgroundTasks/RankingUpdateTask.cs +++ b/League/BackgroundTasks/RankingUpdateTask.cs @@ -132,7 +132,7 @@ await TenantContext.DbContext.AppDb.TeamInRoundRepository.GetTeamInRoundAsync( /***** Ranking table update *****/ // without played matches, neither ranking nor chart can be generated - if (matchesPlayed.All(mp => mp.RoundId != roundId)) + if (matchesPlayed.TrueForAll(mp => mp.RoundId != roundId)) { // Remove an existing ranking list for the round await TenantContext.DbContext.AppDb.RankingRepository.ReplaceAsync(new RankingList(), roundId, cancellationToken); diff --git a/League/Components/MainNavigationComponentModelExtensions.cs b/League/Components/MainNavigationComponentModelExtensions.cs index d36d9068..89d75bc7 100644 --- a/League/Components/MainNavigationComponentModelExtensions.cs +++ b/League/Components/MainNavigationComponentModelExtensions.cs @@ -13,7 +13,7 @@ public static class MainNavigationComponentModelExtensions /// public static bool HasVisibleChildNodes(this MainNavigationComponentModel.NavigationNode node) { - return node.ChildNodes.Any(childNode => childNode.ShouldShow()); + return node.ChildNodes.Exists(childNode => childNode.ShouldShow()); } /// @@ -104,7 +104,7 @@ public static bool IsActiveNode(this MainNavigationComponentModel model, Microso /// if the node is visible and the node url is not null. public static bool ShouldShow(this MainNavigationComponentModel.NavigationNode? node) { - return node != null && (node.IsVisible && node.Url != null || node.ChildNodes.Any(n => n.ShouldShow())); + return node != null && (node is { IsVisible: true, Url: not null } || node.ChildNodes.Exists(n => n.ShouldShow())); } /// diff --git a/League/Controllers/Language.cs b/League/Controllers/Language.cs index 29e24ac6..179f2208 100644 --- a/League/Controllers/Language.cs +++ b/League/Controllers/Language.cs @@ -62,7 +62,7 @@ public IActionResult Index(string? culture, string? uiCulture, string? returnUrl } // Preferred browser language is equal to language selected with query string - if (languages.Length == 0 || languages.First().StartsWith(requestCulture.Name, StringComparison.InvariantCultureIgnoreCase)) + if (languages.Length == 0 || languages[0].StartsWith(requestCulture.Name, StringComparison.InvariantCultureIgnoreCase)) { Response.Cookies.Delete(cookieProvider.CookieName); Response.Cookies.Append(cookieProvider.CookieName, string.Empty, new CookieOptions diff --git a/League/Controllers/Match.cs b/League/Controllers/Match.cs index 1c8e29b7..5a827ad8 100644 --- a/League/Controllers/Match.cs +++ b/League/Controllers/Match.cs @@ -363,7 +363,7 @@ public async Task EnterResult([FromForm] EnterResultViewModel? mo if (permissionValidator.GetFailedFacts().Count != 0) { return View(ViewNames.Match.EnterResultNotAllowed, - (model.Tournament, permissionValidator.GetFailedFacts().First().Message)); + (model.Tournament, permissionValidator.GetFailedFacts()[0].Message)); } model.MapFormFieldsToEntity(); diff --git a/League/Controllers/Ranking.cs b/League/Controllers/Ranking.cs index 196a9f76..1cdf4682 100644 --- a/League/Controllers/Ranking.cs +++ b/League/Controllers/Ranking.cs @@ -85,7 +85,7 @@ public async Task AllTimeTournament(long?id, CancellationToken ca var roundLegPeriods = await GetRoundLegPeriodsCached(rankingList, cancellationToken); id ??= roundLegPeriods.Max(rlp => rlp.TournamentId); - if (roundLegPeriods.Count > 0 && roundLegPeriods.All(rlp => rlp.TournamentId != id)) + if (roundLegPeriods.Count > 0 && roundLegPeriods.TrueForAll(rlp => rlp.TournamentId != id)) return Redirect(TenantLink.Action(nameof(AllTimeTournament), nameof(Ranking), new { id = string.Empty })!); var model = new AllTimeTournamentModel(rankingList, roundLegPeriods) { SelectedTournamentId = id }; @@ -106,7 +106,7 @@ public async Task AllTimeTeam(long? id, CancellationToken cancell var rankingList = await GetRankingListCached(cancellationToken); var roundLegPeriods = await GetRoundLegPeriodsCached(rankingList, cancellationToken); - if (rankingList.Count > 0 && rankingList.All(rl => rl.TeamId != id)) + if (rankingList.Count > 0 && rankingList.TrueForAll(rl => rl.TeamId != id)) return Redirect(TenantLink.Action(nameof(AllTimeTournament), nameof(Ranking), new { id = string.Empty })!); var model = new AllTimeTeamModel(rankingList, roundLegPeriods) { SelectedTeamId = id }; diff --git a/League/Controllers/TeamApplication.cs b/League/Controllers/TeamApplication.cs index bd5a5a11..bae26117 100644 --- a/League/Controllers/TeamApplication.cs +++ b/League/Controllers/TeamApplication.cs @@ -156,7 +156,7 @@ public async Task SelectTeam([FromForm] ApplicationSelectTeamMode public async Task EditTeam(long teamId, CancellationToken cancellationToken) { var teamSelectModel = await GetTeamSelectModel(cancellationToken); - if (teamSelectModel.TeamsManagedByUser.All(t => t.TeamId != teamId)) + if (teamSelectModel.TeamsManagedByUser.TrueForAll(t => t.TeamId != teamId)) { return Redirect(TenantLink.Action(nameof(SelectTeam))!); } @@ -269,7 +269,7 @@ public async Task EditTeam([FromForm] TeamEditModel teamEditModel if (teamEntity.TeamInRounds.Any()) { - var tir = teamEntity.TeamInRounds.First(); + var tir = teamEntity.TeamInRounds[0]; sessionModel.TeamInRound!.MapEntityToFormFields(tir); sessionModel.TeamInRoundIsSet = true; } @@ -493,7 +493,7 @@ public async Task Confirm(bool done, CancellationToken cancellati teamInRoundEntity = (await _appDb.TeamInRoundRepository.GetTeamInRoundAsync( new PredicateExpression(TeamInRoundFields.Id == sessionModel.TeamInRound.Id), - cancellationToken)).First(); + cancellationToken))[0]; } } catch (Exception e) @@ -757,7 +757,7 @@ private async Task AddManagerToTeamEntity(TeamEntity teamEntity, CancellationTok { // Nothing to do, if the current user is already manager of this team var mot = (await _appDb.ManagerOfTeamRepository.GetManagerOfTeamEntitiesAsync(new PredicateExpression(ManagerOfTeamFields.TeamId == teamEntity.Id), - cancellationToken)).FirstOrDefault(u => u.UserId == GetCurrentUserId()); + cancellationToken)).Find(u => u.UserId == GetCurrentUserId()); if (mot == null) { mot = teamEntity.ManagerOfTeams.AddNew(); diff --git a/League/Emailing/Creators/ChangeFixtureCreator.cs b/League/Emailing/Creators/ChangeFixtureCreator.cs index ef09e220..bd8c093d 100644 --- a/League/Emailing/Creators/ChangeFixtureCreator.cs +++ b/League/Emailing/Creators/ChangeFixtureCreator.cs @@ -48,10 +48,10 @@ public async IAsyncEnumerable GetMailMergeMessages(ITenantCont .And(TeamUserRoundFields.TournamentId == tenantContext.TournamentContext.MatchPlanTournamentId)), cancellationToken); - model.Username = teamUserRoundInfos.FirstOrDefault(tur => tur.UserId == Parameters.ChangedByUserId)?.CompleteName; + model.Username = teamUserRoundInfos.Find(tur => tur.UserId == Parameters.ChangedByUserId)?.CompleteName; // User is not a team member, maybe an admin model.Username ??= (await tenantContext.DbContext.AppDb.UserRepository.FindUserAsync( - new PredicateExpression(UserFields.Id == Parameters.ChangedByUserId), 1, cancellationToken)).First() + new PredicateExpression(UserFields.Id == Parameters.ChangedByUserId), 1, cancellationToken))[0] .CompleteName; var plainTextContent = await renderer.RenderAsync(Templates.Email.TemplateName.ChangeFixtureTxt, model, diff --git a/League/Emailing/Creators/ConfirmTeamApplicationCreator.cs b/League/Emailing/Creators/ConfirmTeamApplicationCreator.cs index fb6eb686..74fa64af 100644 --- a/League/Emailing/Creators/ConfirmTeamApplicationCreator.cs +++ b/League/Emailing/Creators/ConfirmTeamApplicationCreator.cs @@ -35,7 +35,7 @@ public async IAsyncEnumerable GetMailMergeMessages(ITenantCont var roundWithType = (await tenantContext.DbContext.AppDb.RoundRepository.GetRoundsWithTypeAsync( new PredicateExpression( RoundFields.TournamentId == tenantContext.TournamentContext.ApplicationTournamentId & - RoundFields.Id == Parameters.RoundId), cancellationToken)).First(); + RoundFields.Id == Parameters.RoundId), cancellationToken))[0]; var teamUserRoundInfos = await tenantContext.DbContext.AppDb.TeamRepository.GetTeamUserRoundInfosAsync( new PredicateExpression(TeamUserRoundFields.TeamId == Parameters.TeamId & diff --git a/League/Emailing/Creators/ResultEnteredCreator.cs b/League/Emailing/Creators/ResultEnteredCreator.cs index e707a557..88db48d4 100644 --- a/League/Emailing/Creators/ResultEnteredCreator.cs +++ b/League/Emailing/Creators/ResultEnteredCreator.cs @@ -42,10 +42,10 @@ public async IAsyncEnumerable GetMailMergeMessages(ITenantCont .And(TeamUserRoundFields.TournamentId == tenantContext.TournamentContext.MatchResultTournamentId)), cancellationToken); - var username = teamUserRoundInfos.FirstOrDefault(tur => tur.UserId == Parameters.ChangedByUserId)?.CompleteName; + var username = teamUserRoundInfos.Find(tur => tur.UserId == Parameters.ChangedByUserId)?.CompleteName; // User is not a team member, maybe an admin username ??= (await tenantContext.DbContext.AppDb.UserRepository.FindUserAsync( - new PredicateExpression(UserFields.Id == Parameters.ChangedByUserId), 1, cancellationToken)).First() + new PredicateExpression(UserFields.Id == Parameters.ChangedByUserId), 1, cancellationToken))[0] .CompleteName; var model = new ResultEnteredModel diff --git a/League/LeagueStartup.cs b/League/LeagueStartup.cs index 4cb39cf0..fcce4d92 100644 --- a/League/LeagueStartup.cs +++ b/League/LeagueStartup.cs @@ -150,7 +150,7 @@ public static void ConfigureServices(WebApplicationBuilder builder, ILoggerFacto }.LoadTenants(); var tenants = store.GetTenants().Values.ToList(); - if (!tenants.Any(t => t.IsDefault)) throw new InvalidOperationException("No default tenant configuration found."); + if (!tenants.Exists(t => t.IsDefault)) throw new InvalidOperationException("No default tenant configuration found."); tenants.ForEach(t => { if (string.IsNullOrWhiteSpace(t.DbContext.ConnectionString)) diff --git a/League/Models/MapViewModels/MapModel.cs b/League/Models/MapViewModels/MapModel.cs index f99435f2..7af5d904 100644 --- a/League/Models/MapViewModels/MapModel.cs +++ b/League/Models/MapViewModels/MapModel.cs @@ -46,7 +46,7 @@ private void PrepareAllVenues() { var locationJsObject = new StringBuilder("\n"); - if (!Venues.Any(v => v.Longitude.HasValue && v.Latitude.HasValue)) + if (!Venues.Exists(v => v is { Longitude: not null, Latitude: not null })) return; MaxLongitude = Venues.Max(l => l.Longitude)?.ToString("###.########", System.Globalization.CultureInfo.InvariantCulture); diff --git a/League/Models/RankingViewModels/AllTimeTeamModel.cs b/League/Models/RankingViewModels/AllTimeTeamModel.cs index 3b42de5e..aa72a388 100644 --- a/League/Models/RankingViewModels/AllTimeTeamModel.cs +++ b/League/Models/RankingViewModels/AllTimeTeamModel.cs @@ -17,7 +17,7 @@ public AllTimeTeamModel(List rankingList, List rl.TeamId == SelectedTeamId); + var rankRow = RankingList.Find(rl => rl.TeamId == SelectedTeamId); if (rankRow == null) return (string.Empty, string.Empty); return (rankRow.TeamName, rankRow.ClubName); diff --git a/League/Models/TeamViewModels/TeamEditModel.cs b/League/Models/TeamViewModels/TeamEditModel.cs index 0b5fd11c..fe375392 100644 --- a/League/Models/TeamViewModels/TeamEditModel.cs +++ b/League/Models/TeamViewModels/TeamEditModel.cs @@ -35,7 +35,7 @@ public void MapFormFieldsToEntity() if (TeamEntity!.TeamInRounds.Any()) { // Only the RoundId is updated, but not the TeamNameForRound! - TeamEntity.TeamInRounds.First().RoundId = Round.SelectedRoundId.Value; + TeamEntity.TeamInRounds[0].RoundId = Round.SelectedRoundId.Value; } else { diff --git a/League/TagHelpers/Modal/SiteModalToggleTagHelper.cs b/League/TagHelpers/Modal/SiteModalToggleTagHelper.cs index 01d58889..0ee39d67 100644 --- a/League/TagHelpers/Modal/SiteModalToggleTagHelper.cs +++ b/League/TagHelpers/Modal/SiteModalToggleTagHelper.cs @@ -23,6 +23,6 @@ public class SiteModalToggleTagHelper : TagHelper public override void Process(TagHelperContext context, TagHelperOutput output) { output.Attributes.SetAttribute("data-bs-toggle", "modal"); - output.Attributes.SetAttribute("data-bs-target", ToggleModal != null && ToggleModal.StartsWith("#") ? ToggleModal : $"#{ToggleModal}"); + output.Attributes.SetAttribute("data-bs-target", ToggleModal != null && ToggleModal.StartsWith('#') ? ToggleModal : $"#{ToggleModal}"); } } diff --git a/League/Views/Map/Index.cshtml b/League/Views/Map/Index.cshtml index 7db011c1..20e1fb4f 100644 --- a/League/Views/Map/Index.cshtml +++ b/League/Views/Map/Index.cshtml @@ -2,7 +2,7 @@ @model League.Models.MapViewModels.MapModel @inject IViewLocalizer Localizer @{ ViewData["Title"] = Localizer["Venues"].Value + " - " + Model.Tournament?.Name;} - @if (!Model.Venues.Any(v => v is { Latitude: not null, Longitude: not null })) + @if (!Model.Venues.Exists(v => v is { Latitude: not null, Longitude: not null })) {
@@ -21,7 +21,7 @@

@ViewData["Title"]

@if (Model.IsSingleValue) { - var venue = Model.Venues.First(); + var venue = Model.Venues[0];

@venue.VenueName


} diff --git a/League/Views/Match/Fixtures.cshtml b/League/Views/Match/Fixtures.cshtml index 2c0c3e0c..f78baafc 100644 --- a/League/Views/Match/Fixtures.cshtml +++ b/League/Views/Match/Fixtures.cshtml @@ -30,7 +30,7 @@ var activeRoundId = Model.ActiveRoundId ?? 0; var rounds = Model.PlannedMatches.GroupBy(m => m.RoundName, (key, m) => new { RoundName = key, RoundId = m.First().RoundId, RoundDescription = m.First().RoundDescription, RoundTypeDescription = m.First().RoundTypeDescription }) .OrderBy(m => m.RoundName).ToList(); - var useRecentRoundCookie = !(Model.ActiveRoundId.HasValue && rounds.Any(r => r.RoundId == Model.ActiveRoundId)); + var useRecentRoundCookie = !(Model.ActiveRoundId.HasValue && rounds.Exists(r => r.RoundId == Model.ActiveRoundId)); if (useRecentRoundCookie) { activeRoundId = rounds.FirstOrDefault()?.RoundId ?? 0; } string FmtDate(DateTime? matchDate) diff --git a/League/Views/Match/Results.cshtml b/League/Views/Match/Results.cshtml index c03e296a..8145a05c 100644 --- a/League/Views/Match/Results.cshtml +++ b/League/Views/Match/Results.cshtml @@ -28,7 +28,7 @@ var rounds = Model.CompletedMatches .GroupBy(m => m.RoundName, (key, m) => new { RoundName = key, RoundId = m.First().RoundId, RoundDescription = m.First().RoundDescription, RoundTypeDescription = m.First().RoundTypeDescription }) .OrderBy(m => m.RoundName).ToList(); - var useRecentRoundCookie = !(Model.ActiveRoundId.HasValue && rounds.Any(r => r.RoundId == Model.ActiveRoundId)); + var useRecentRoundCookie = !(Model.ActiveRoundId.HasValue && rounds.Exists(r => r.RoundId == Model.ActiveRoundId)); if (useRecentRoundCookie) { activeRoundId = rounds.FirstOrDefault()?.RoundId ?? 0; } MatchEntity ToMatchEntity(CompletedMatchRow cmr) { @@ -171,7 +171,7 @@
@{ - if (Model.CompletedMatches.Any(m => m.RoundId == r.RoundId && m.IsOverruled)) + if (Model.CompletedMatches.Exists(m => m.RoundId == r.RoundId && m.IsOverruled)) {
@(overruled) = @Localizer["Awarded points were adjusted manually"]. diff --git a/League/Views/Ranking/Table.cshtml b/League/Views/Ranking/Table.cshtml index 3663fc28..3d55a7d0 100644 --- a/League/Views/Ranking/Table.cshtml +++ b/League/Views/Ranking/Table.cshtml @@ -26,7 +26,7 @@ .GroupBy(m => m.RoundName, (key, m) => new { RoundName = key, RoundId = m.First() .RoundId, RoundDescription = m.First().RoundDescription, RoundTypeDescription = m.First().RoundTypeDescription }) .OrderBy(m => m.RoundName).ToList(); - var useRecentRoundCookie = !(Model.ActiveRoundId.HasValue && rounds.Any(r => r.RoundId == Model.ActiveRoundId)); + var useRecentRoundCookie = !(Model.ActiveRoundId.HasValue && rounds.Exists(r => r.RoundId == Model.ActiveRoundId)); if (useRecentRoundCookie) { activeRoundId = rounds.FirstOrDefault()?.RoundId ?? 0; } } @functions { diff --git a/League/Views/Team/MyTeam.cshtml b/League/Views/Team/MyTeam.cshtml index 31e07e0b..614ee4d1 100644 --- a/League/Views/Team/MyTeam.cshtml +++ b/League/Views/Team/MyTeam.cshtml @@ -44,7 +44,7 @@ var teamPhotoInfo = Model.TeamPhotoStaticFile!.GetUriInfo(teamVenueInfo.TeamId); var zonedLastModified = Model.TimeZoneConverter.ToZonedTime(teamPhotoInfo.Date)!; -
+
diff --git a/TournamentManager/DAL/DatabaseGeneric/CustomExtensions/UserEntity.cs b/TournamentManager/DAL/DatabaseGeneric/CustomExtensions/UserEntity.cs index 598cf4d1..a1665629 100644 --- a/TournamentManager/DAL/DatabaseGeneric/CustomExtensions/UserEntity.cs +++ b/TournamentManager/DAL/DatabaseGeneric/CustomExtensions/UserEntity.cs @@ -37,10 +37,10 @@ public string CompleteNameWithNickName public bool IsPlayer => PlayerInTeams.Any(); [XmlIgnore] - public bool DataCompleteAsManager => (new[] {FirstName, LastName, PhoneNumber, Email}).All(s => !string.IsNullOrWhiteSpace(s)); + public bool DataCompleteAsManager => (new List {FirstName, LastName, PhoneNumber, Email}).TrueForAll(s => !string.IsNullOrWhiteSpace(s)); [XmlIgnore] - public bool DataCompleteAsPerson => (new[] { FirstName, LastName, Email }).All(s => !string.IsNullOrWhiteSpace(s)); + public bool DataCompleteAsPerson => (new List { FirstName, LastName, Email }).TrueForAll(s => !string.IsNullOrWhiteSpace(s)); protected override void OnSetValue(int fieldIndex, object valueToSet, out bool cancel) { diff --git a/TournamentManager/DAL/DatabaseSpecific/CustomExtensions/QueryCreationManagerExt.cs b/TournamentManager/DAL/DatabaseSpecific/CustomExtensions/QueryCreationManagerExt.cs index afad04e3..f09bddcc 100644 --- a/TournamentManager/DAL/DatabaseSpecific/CustomExtensions/QueryCreationManagerExt.cs +++ b/TournamentManager/DAL/DatabaseSpecific/CustomExtensions/QueryCreationManagerExt.cs @@ -32,7 +32,7 @@ public string GetPersistentFieldName(IEntityField2 field) /// Returns the source table name an belongs to in the persistent storage. public string GetPersistentTableName(IEntity2 entity) { - var i = GetFieldPersistenceInfo(entity.PrimaryKeyFields.First()); + var i = GetFieldPersistenceInfo(entity.PrimaryKeyFields[0]); return i.SourceObjectName; } -} \ No newline at end of file +} diff --git a/TournamentManager/TournamentManager/Data/TeamRespository.cs b/TournamentManager/TournamentManager/Data/TeamRespository.cs index 2599a880..08a9e658 100644 --- a/TournamentManager/TournamentManager/Data/TeamRespository.cs +++ b/TournamentManager/TournamentManager/Data/TeamRespository.cs @@ -127,6 +127,6 @@ static string Sanitize(string name) using var da = _dbContext.GetNewAdapter(); var teamNames = await da.FetchQueryAsync(new QueryFactory().Create().Select(() => TeamFields.Name.ToValue()).Where(TeamFields.Id != teamEntity.Id), cancellationToken); - return teamNames.FirstOrDefault(tn => Sanitize(tn).Equals(Sanitize(teamEntity.Name))); + return teamNames.Find(tn => Sanitize(tn).Equals(Sanitize(teamEntity.Name))); } } diff --git a/TournamentManager/TournamentManager/ModelValidators/FixtureValidator.cs b/TournamentManager/TournamentManager/ModelValidators/FixtureValidator.cs index f71d85ad..769478d9 100644 --- a/TournamentManager/TournamentManager/ModelValidators/FixtureValidator.cs +++ b/TournamentManager/TournamentManager/ModelValidators/FixtureValidator.cs @@ -101,7 +101,7 @@ async Task FactResult(CancellationToken cancellationToken) ? (await Data.TenantContext.DbContext.AppDb.VenueRepository.GetOccupyingMatchesAsync( Model.VenueId.Value, new DateTimePeriod(Model.PlannedStart, Model.PlannedEnd), Data.TenantContext.TournamentContext.MatchPlanTournamentId, cancellationToken)) - .FirstOrDefault(m => m.Id != Model.Id) + .Find(m => m.Id != Model.Id) : null; return new FactResult @@ -146,8 +146,8 @@ async Task FactResult(CancellationToken cancellationToken) if (!Model.VenueId.HasValue || !Model.PlannedStart.HasValue) return _successResult; await LoadTeamsInMatch(cancellationToken); - var homeTeam = _teamsInMatch.FirstOrDefault(m => m.Id == Model.HomeTeamId); - var guestTeam = _teamsInMatch.FirstOrDefault(m => m.Id == Model.GuestTeamId); + var homeTeam = _teamsInMatch.Find(m => m.Id == Model.HomeTeamId); + var guestTeam = _teamsInMatch.Find(m => m.Id == Model.GuestTeamId); var plannedStartDayOfWeek = (int?) Model.PlannedStart.Value.DayOfWeek; if (homeTeam?.MatchDayOfWeek == null || guestTeam?.MatchDayOfWeek == null) return _successResult; @@ -213,7 +213,7 @@ async Task FactResult(CancellationToken cancellationToken) { Message = string.Format(FixtureValidatorResource.ResourceManager.GetString( nameof(FactId.PlannedStartTeamsAreNotBusy)) ?? string.Empty, - Data.PlannedMatch.HomeTeamId == busyTeams.First() + Data.PlannedMatch.HomeTeamId == busyTeams[0] ? Data.PlannedMatch.HomeTeamNameForRound : Data.PlannedMatch.GuestTeamNameForRound), Success = busyTeams.Length == 0 diff --git a/TournamentManager/TournamentManager/ModelValidators/SetsValidator.cs b/TournamentManager/TournamentManager/ModelValidators/SetsValidator.cs index 9754c9d0..720724fa 100644 --- a/TournamentManager/TournamentManager/ModelValidators/SetsValidator.cs +++ b/TournamentManager/TournamentManager/ModelValidators/SetsValidator.cs @@ -131,7 +131,7 @@ Task FactResult() if (Data.Rules.MatchRule.BestOf && Data.Rules.MatchRule.MaxNumOfSets() == Model.Count) { - factResult.Success = Model.Last().IsTieBreak; + factResult.Success = Model[^1].IsTieBreak; } return Task.FromResult(factResult); diff --git a/TournamentManager/TournamentManager/ModelValidators/VenueValidator.cs b/TournamentManager/TournamentManager/ModelValidators/VenueValidator.cs index eb00d535..86217c4f 100644 --- a/TournamentManager/TournamentManager/ModelValidators/VenueValidator.cs +++ b/TournamentManager/TournamentManager/ModelValidators/VenueValidator.cs @@ -112,7 +112,7 @@ private Fact AddressFieldsAreSet() new FactResult { Message = VenueValidatorResource.AddressFieldsAreSet, - Success = new[] {Model.PostalCode, Model.City, Model.Street}.All(f => !string.IsNullOrWhiteSpace(f)) + Success = new List {Model.PostalCode, Model.City, Model.Street}.TrueForAll(f => !string.IsNullOrWhiteSpace(f)) }) }; } diff --git a/TournamentManager/TournamentManager/Plan/MatchScheduler.cs b/TournamentManager/TournamentManager/Plan/MatchScheduler.cs index eb117d85..929af947 100644 --- a/TournamentManager/TournamentManager/Plan/MatchScheduler.cs +++ b/TournamentManager/TournamentManager/Plan/MatchScheduler.cs @@ -190,7 +190,7 @@ private void SetMatchDates(RoundEntity round, RoundLegEntity roundLeg, VenueId = datesFound[index] != null ? datesFound[index]!.VenueId // take over the venue stored in the team entity (may also be null!) - : _tournament.Rounds[_tournament.Rounds.FindMatches(RoundFields.Id == roundLeg.RoundId).First()] + : _tournament.Rounds[_tournament.Rounds.FindMatches(RoundFields.Id == roundLeg.RoundId)[0]] .TeamCollectionViaTeamInRound.First(t => t.Id == combination.Home).VenueId, RoundId = round.Id, IsComplete = false, diff --git a/TournamentManager/TournamentManager/Ranking/RankingChart.cs b/TournamentManager/TournamentManager/Ranking/RankingChart.cs index a11846f0..522b0f15 100644 --- a/TournamentManager/TournamentManager/Ranking/RankingChart.cs +++ b/TournamentManager/TournamentManager/Ranking/RankingChart.cs @@ -191,7 +191,7 @@ public PlotModel CreatePlotModel() lineSeries.Points.Add(new DataPoint(i, teamRankingHistory.Last().Number)); } - var teamName = _teams.FirstOrDefault(t => t.TeamId == lastRank.TeamId).TeamName; + var teamName = _teams.Find(t => t.TeamId == lastRank.TeamId).TeamName; if (string.IsNullOrEmpty(teamName)) teamName = "?"; lineSeries.Title = teamName; model.Series.Add(lineSeries);