83522ac52c
Updated the Teams Index and Printout components to prioritize sorting by EventFormat, enhancing the organization of team data. Introduced a regional filter toggle in the Teams Index to allow users to view only regional teams. Adjusted the ScheduledTeamsList to sort teams by EventFormat first, ensuring consistent ordering across components. Additionally, added necessary using directives for improved code clarity.
47 lines
2.0 KiB
C#
47 lines
2.0 KiB
C#
using Core.Entities;
|
|
|
|
namespace WebApp.Models;
|
|
|
|
/// <summary>
|
|
/// Extension methods for sorting teams with group teams (EventFormat.Team) appearing before individual teams (EventFormat.Individual).
|
|
/// </summary>
|
|
public static class TeamExtensions
|
|
{
|
|
/// <summary>
|
|
/// Orders teams with group teams (EventFormat.Team) first, then individual teams (EventFormat.Individual).
|
|
/// For use with EF Core IQueryable queries.
|
|
/// </summary>
|
|
/// <param name="teams">The queryable collection of teams to sort.</param>
|
|
/// <returns>An ordered queryable with group teams first, then individual teams.</returns>
|
|
public static IOrderedQueryable<Team> OrderByEventFormatFirst(this IQueryable<Team> teams)
|
|
{
|
|
return teams.OrderByDescending(t => t.Event.EventFormat == EventFormat.Team ? 1 : 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Orders teams with group teams (EventFormat.Team) first, then individual teams (EventFormat.Individual).
|
|
/// For use with in-memory IEnumerable collections.
|
|
/// </summary>
|
|
/// <param name="teams">The collection of teams to sort.</param>
|
|
/// <returns>An ordered enumerable with group teams first, then individual teams.</returns>
|
|
public static IOrderedEnumerable<Team> OrderByEventFormatFirst(this IEnumerable<Team> teams)
|
|
{
|
|
return teams.OrderByDescending(t => t.Event.EventFormat == EventFormat.Team ? 1 : 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Orders teams with group teams first, then applies default secondary sorting:
|
|
/// Event.Name (ascending), then Identifier (ascending with nulls last).
|
|
/// </summary>
|
|
/// <param name="teams">The collection of teams to sort.</param>
|
|
/// <returns>An ordered enumerable with group teams first and default secondary sorting applied.</returns>
|
|
public static IOrderedEnumerable<Team> OrderByEventFormatFirstWithDefaults(this IEnumerable<Team> teams)
|
|
{
|
|
return teams
|
|
.OrderByEventFormatFirst()
|
|
.ThenBy(t => t.Event.Name)
|
|
.ThenBy(t => t.Identifier ?? "");
|
|
}
|
|
}
|
|
|