diff --git a/DataLayer/EfClasses/Book.cs b/DataLayer/EfClasses/Book.cs index 4aee9b8c..2dba71d5 100644 --- a/DataLayer/EfClasses/Book.cs +++ b/DataLayer/EfClasses/Book.cs @@ -51,6 +51,9 @@ public string[] CategoriesIds : Category.ParentCategory is null ? new[] { Category.AudibleCategoryId } : new[] { Category.ParentCategory.AudibleCategoryId, Category.AudibleCategoryId }; + public string TitleSortable => Formatters.GetSortName(Title); + public string SeriesSortable => Formatters.GetSortName(SeriesNames); + // is owned, not optional 1:1 public UserDefinedItem UserDefinedItem { get; private set; } diff --git a/DataLayer/Formatters.cs b/DataLayer/Formatters.cs new file mode 100644 index 00000000..8243901c --- /dev/null +++ b/DataLayer/Formatters.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace DataLayer +{ + internal class Formatters + { + private static string[] _sortPrefixIgnores { get; } = { "the", "a", "an" }; + + public static string GetSortName(string unformattedName) + { + var sortName = unformattedName + .Replace("|", "") + .Replace(":", "") + .ToLowerInvariant() + .Trim(); + + if (_sortPrefixIgnores.Any(prefix => sortName.StartsWith(prefix + " "))) + sortName = sortName + .Substring(sortName.IndexOf(" ") + 1) + .TrimStart(); + + return sortName; + } + } +} diff --git a/LibationWinForms/grid/GridEntry.cs b/LibationWinForms/grid/GridEntry.cs index 817c7657..45afd23d 100644 --- a/LibationWinForms/grid/GridEntry.cs +++ b/LibationWinForms/grid/GridEntry.cs @@ -209,8 +209,8 @@ private void Commit() /// private Dictionary> CreateMemberValueDictionary() => new() { - { nameof(Title), () => GetSortName(Book.Title) }, - { nameof(Series), () => GetSortName(Book.SeriesNames) }, + { nameof(Title), () => Book.TitleSortable }, + { nameof(Series), () => Book.SeriesSortable }, { nameof(Length), () => Book.LengthInMinutes }, { nameof(MyRating), () => Book.UserDefinedItem.Rating.FirstScore }, { nameof(PurchaseDate), () => LibraryBook.DateAdded }, @@ -234,21 +234,6 @@ private void Commit() { typeof(LiberatedStatus), new ObjectComparer() }, }; - private static readonly string[] _sortPrefixIgnores = { "the", "a", "an" }; - private static string GetSortName(string unformattedName) - { - var sortName = unformattedName - .Replace("|", "") - .Replace(":", "") - .ToLowerInvariant() - .Trim(); - - if (_sortPrefixIgnores.Any(prefix => sortName.StartsWith(prefix + " "))) - sortName = sortName.Substring(sortName.IndexOf(" ") + 1).TrimStart(); - - return sortName; - } - #endregion #region Static library display functions