private string GetSortLabel(ItemSortOption sort) { return(sort switch { ItemSortOption.Name => I18n.Sort_ByName(), ItemSortOption.Category => I18n.Sort_ByCategory(), ItemSortOption.ID => I18n.Sort_ById(), _ => throw new NotSupportedException($"Invalid sort type {sort}.") });
public static ItemSortOption GetNext(this ItemSortOption current) { return(current switch { ItemSortOption.Name => ItemSortOption.Category, ItemSortOption.Category => ItemSortOption.ID, ItemSortOption.ID => ItemSortOption.Name, _ => throw new NotSupportedException($"Unknown sort '{current}'.") });
/// <summary> /// Sorts using the selected option /// </summary> public List <ItemModel> Sort(IEnumerable <ItemModel> items, ItemSortOption sortOption) { if (sortOption == ItemSortOption.Name_Ascending) { items = items.OrderBy(x => x.Name); } else if (sortOption == ItemSortOption.Name_Descending) { items = items.OrderByDescending(x => x.Name); } else if (sortOption == ItemSortOption.Type_Ascending) { items = items.OrderBy(x => x.Type); } else if (sortOption == ItemSortOption.Type_Descending) { items = items.OrderByDescending(x => x.Type); } else if (sortOption == ItemSortOption.Value_Ascending) { items = items.OrderBy(x => { float.TryParse(x.Value, out float v); return(v); }); } else if (sortOption == ItemSortOption.Value_Descending) { items = items.OrderByDescending(x => { float.TryParse(x.Value, out float v); return(v); }); } else if (sortOption == ItemSortOption.Weight_Ascending) { items = items.OrderBy(x => { int.TryParse(x.Weight, out int w); return(w); }); } else if (sortOption == ItemSortOption.Weight_Descending) { items = items.OrderByDescending(x => { int.TryParse(x.Weight, out int w); return(w); }); } return(items.ToList()); }